pop-os / async-cron-scheduler

Runtime-agnostic async task scheduler with cron expression support
Mozilla Public License 2.0
5 stars 1 forks source link

May I ask if it is possible to execute asynchronous function tasks on actix_web? #2

Open sunkaifei opened 1 week ago

sunkaifei commented 1 week ago

Hello author, Because my actix_web program requires scheduled data addition, deletion, modification, and querying operations, can you use your async-cron-scheduler to complete them? for example:

scheduler.insert(job, |_id| println!("Buzz")).await;

How do I write to execute one or more asynchronous functions at position println!("Buzz")?

mmstick commented 1 week ago

You can use any means you want. One could be sending a message through an async channel that asynchronously responds to those messages in another event loop. Another is to spawn a future onto your runtime.

sunkaifei commented 1 week ago

For example, when starting the program, there may be a task scheduling list with N tasks to be executed. How to load these tasks at once, or the task may be halfway completed or the service may be shut down when it is about to be executed. After restarting, the execution time of this task may have passed. How can this task continue to be executed? I also hope to have some examples of how to use actix_web

mmstick commented 1 week ago

As I mentioned, you can emit signals through an async channel, or spawn a future onto your runtime. The purpose of this library is to asynchronously schedule jobs at the intervals defined by the job's cron expression.

sunkaifei commented 1 week ago

Thank you for your reply. I am new to learning Rust and not yet familiar with it. I used to study Java and have just switched over. If it is convenient for you, could you write an example of executing asynchronous task scheduling in the actix_web framework? thank you!

mmstick commented 1 week ago

I have no experience with actix_web, and I do not know what you're trying to do. So I can't provide any domain-specific examples. If you're new to Rust, I'd recommend https://www.manning.com/books/learn-rust-in-a-month-of-lunches. If you want recommendations of async channels, you can check out tachyonix, async-channel, and tokio's mpsc channel. There are also a handful of books specific to async and web development, such as https://www.zero2prod.com/index.html and https://www.manning.com/books/rust-web-development