File tree 4 files changed +32
-3
lines changed
4 files changed +32
-3
lines changed Original file line number Diff line number Diff line change 1
1
/target
2
2
/Cargo.lock
3
- /tests
3
+ /tests
4
+ /.idea
Original file line number Diff line number Diff line change @@ -7,12 +7,15 @@ use std::sync::{Arc, RwLock};
7
7
use tokio:: task:: JoinHandle ;
8
8
use crate :: job_storage:: JobStorage ;
9
9
10
-
10
+ /// `JobExecutor` is used to execute jobs
11
11
pub trait JobExecutor : Send + Sync {
12
+ /// start job execution
12
13
fn start ( & self ) ->JoinHandle < ( ) > ;
14
+ /// stop job execution and wait for all running jobs to complete
13
15
fn stop ( & self ) ->Pin < Box < dyn Future < Output = ( ) > > > ;
14
16
}
15
17
18
+ /// Default implementation for `JobExecutor`
16
19
pub struct DefaultJobExecutor < Tz : chrono:: TimeZone + Send + Sync > {
17
20
jobs : Arc < dyn JobStorage < Tz > > ,
18
21
tasks : Arc < RwLock < Vec < JoinHandle < ( ) > > > > ,
Original file line number Diff line number Diff line change @@ -68,6 +68,9 @@ pub trait JobStorage<Tz: chrono::TimeZone + Send + Sync>: Send + Sync {
68
68
async fn restore_jobs ( & self ) -> Result < ( ) , SchedulerError > ;
69
69
}
70
70
71
+ /// Simple Memory Job Storage implements `JobStorage`
72
+ ///
73
+ /// !!! This JobStorage is not recommended for production environment !!!
71
74
pub struct MemoryJobStorage < Tz = chrono:: Utc >
72
75
where Tz : chrono:: TimeZone + Sync + Send
73
76
{
Original file line number Diff line number Diff line change
1
+ //! # TOKIO-SCHEDULER-RS
2
+ //!
3
+ //! Yet Another JobScheduler
4
+ //!
5
+ //! # Example
6
+ //! ```rust
7
+ //! # use tokio_scheduler_rs::job_scheduler::JobScheduler;
8
+ //! let scheduler = JobScheduler::default_with_timezone(chrono_tz::PRC);
9
+ //! scheduler.register_job(Box::new(HelloWorldJob)).unwrap();
10
+ //! scheduler.add_job("HelloWorldJob".into(),"*/5 * * * * * *".into(),None).await.unwrap();
11
+ //! scheduler.restore_jobs().await.unwrap(); // This step is used to restore job execute status.
12
+ //! // Please notice that you can implement you own job storage to store job status.
13
+ //! scheduler.start().await.unwrap(); // `start()` returns a tokio::JoinHandle<()>, you can continue this program if you don't await it.
14
+ //! ```
15
+
1
16
pub mod job_storage;
2
17
pub mod errors;
3
18
pub mod job;
4
19
pub mod job_scheduler;
5
20
pub mod job_executor;
6
- pub use serde_json;
21
+ pub use serde_json;
22
+ pub use async_trait;
23
+ pub use job:: ScheduleJob ;
24
+ pub use job_storage:: JobStorage ;
25
+ pub use job_scheduler:: JobScheduler ;
26
+ pub use job_executor:: JobExecutor ;
27
+ pub use job_storage:: MemoryJobStorage ;
28
+ pub use job_executor:: DefaultJobExecutor ;
You can’t perform that action at this time.
0 commit comments