diff --git a/examples/lib.rs b/examples/lib.rs index 3ca7463..ecc079f 100644 --- a/examples/lib.rs +++ b/examples/lib.rs @@ -8,11 +8,11 @@ pub async fn run_example(sched: &mut JobScheduler) -> Result, JobSched #[cfg(feature = "signal")] sched.shutdown_on_ctrl_c(); - sched.set_shutdown_handler(Box::new(|| { - Box::pin(async move { + sched + .set_shutdown_handler(async move { info!("Shut down done"); }) - })); + .await; let mut five_s_job = Job::new("1/5 * * * * *", |uuid, _l| { info!( @@ -27,7 +27,7 @@ pub async fn run_example(sched: &mut JobScheduler) -> Result, JobSched // the job store, but with stopped marking five_s_job .on_removed_notification_add( - &sched, + sched, Box::new(|job_id, notification_id, type_of_notification| { Box::pin(async move { info!( @@ -55,7 +55,7 @@ pub async fn run_example(sched: &mut JobScheduler) -> Result, JobSched let four_s_job_async_clone = four_s_job_async.clone(); let js = sched.clone(); info!("4s job id {:?}", four_s_job_async.guid()); - four_s_job_async.on_start_notification_add(&sched, Box::new(move |job_id, notification_id, type_of_notification| { + four_s_job_async.on_start_notification_add(sched, Box::new(move |job_id, notification_id, type_of_notification| { let four_s_job_async_clone = four_s_job_async_clone.clone(); let js = js.clone(); Box::pin(async move { @@ -67,7 +67,7 @@ pub async fn run_example(sched: &mut JobScheduler) -> Result, JobSched four_s_job_async .on_done_notification_add( - &sched, + sched, Box::new(|job_id, notification_id, type_of_notification| { Box::pin(async move { info!( diff --git a/examples/repeated_with_start_at.rs b/examples/repeated_with_start_at.rs index 8e64fe1..ef2f39c 100644 --- a/examples/repeated_with_start_at.rs +++ b/examples/repeated_with_start_at.rs @@ -4,7 +4,7 @@ use tokio_cron_scheduler::{JobBuilder, JobScheduler}; #[tokio::main] async fn main() { - println!("start at: {}", Local::now().to_rfc3339().to_string()); + println!("start at: {:?}", Local::now().to_rfc3339()); // 创建 scheduler let mut sched = JobScheduler::new().await.unwrap(); @@ -26,11 +26,11 @@ async fn main() { .start_at(datetime) // TODO:设置 job 的任务重叠策略 // 设置 job 的异步执行函数 - .with_run_async(Box::new(|uuid, mut l| { + .with_run_async(Box::new(|_uuid, mut _l| { Box::pin(async move { - println!(">>> {}", Local::now().to_rfc3339().to_string()); + println!(">>> {:?}", Local::now().to_rfc3339()); tokio::time::sleep(Duration::from_secs(INTERVAL + 2)).await; - println!("<<< {}", Local::now().to_rfc3339().to_string()); + println!("<<< {:?}", Local::now().to_rfc3339()); }) })) .build() @@ -49,5 +49,5 @@ async fn main() { // 停止 scheduler sched.shutdown().await.unwrap(); - println!("stop at: {}", Local::now().to_rfc3339().to_string()); + println!("stop at: {:?}", Local::now().to_rfc3339()); } diff --git a/src/job/builder.rs b/src/job/builder.rs index 15e667e..ea06b50 100644 --- a/src/job/builder.rs +++ b/src/job/builder.rs @@ -50,6 +50,12 @@ impl JobBuilder { } } +impl Default for JobBuilder { + fn default() -> Self { + Self::new() + } +} + impl JobBuilder { pub fn with_timezone(self, timezone: U) -> JobBuilder { JobBuilder { diff --git a/src/job/mod.rs b/src/job/mod.rs index c0c9719..2e7c22a 100644 --- a/src/job/mod.rs +++ b/src/job/mod.rs @@ -60,6 +60,7 @@ fn nop_async(_uuid: Uuid, _jobs: JobsSchedulerLocked) -> Pin>>); pub trait Job { + #[allow(dead_code)] fn is_cron_job(&self) -> bool; fn schedule(&self) -> Option; fn repeated_every(&self) -> Option; @@ -69,17 +70,20 @@ pub trait Job { fn set_next_tick(&mut self, tick: Option>); fn set_count(&mut self, count: u32); fn count(&self) -> u32; + #[allow(dead_code)] fn increment_count(&mut self); fn job_id(&self) -> Uuid; fn job_type(&self) -> JobType; fn ran(&self) -> bool; fn set_ran(&mut self, ran: bool); + #[allow(dead_code)] fn stop(&self) -> bool; fn set_stopped(&mut self); fn set_started(&mut self); fn job_data_from_job(&mut self) -> Result, JobSchedulerError>; fn set_job_data(&mut self, job_data: JobStoredData) -> Result<(), JobSchedulerError>; fn run(&mut self, jobs: JobScheduler) -> Receiver; + #[allow(dead_code)] fn fixed_offset_west(&self) -> i32; } diff --git a/src/job_scheduler.rs b/src/job_scheduler.rs index cfd7e31..ead3c96 100644 --- a/src/job_scheduler.rs +++ b/src/job_scheduler.rs @@ -8,7 +8,7 @@ use crate::simple::{ SimpleJobCode, SimpleMetadataStore, SimpleNotificationCode, SimpleNotificationStore, }; use crate::store::{MetaDataStorage, NotificationStore}; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, Utc}; use std::future::Future; use std::pin::Pin; use std::sync::atomic::{AtomicBool, Ordering}; @@ -331,15 +331,12 @@ impl JobsSchedulerLocked { let mut metadata = self.context.metadata_storage.write().await; let jm = metadata.get(job_id).await?; - match jm { - Some(mut job_metadata) => { - job_metadata - .last_updated - .replace(Utc::now().timestamp() as u64); - job_metadata.ran = ran; - metadata.add_or_update(job_metadata).await?; - } - _ => {} + if let Some(mut job_metadata) = jm { + job_metadata + .last_updated + .replace(Utc::now().timestamp() as u64); + job_metadata.ran = ran; + metadata.add_or_update(job_metadata).await?; } Ok(()) } @@ -410,10 +407,7 @@ impl JobsSchedulerLocked { if vv.next_tick == 0 { return None; } - match NaiveDateTime::from_timestamp_opt(vv.next_tick as i64, 0) { - None => None, - Some(ts) => Some(DateTime::from_naive_utc_and_offset(ts, Utc)), - } + DateTime::from_timestamp(vv.next_tick as i64, 0) } else { None } diff --git a/src/scheduler.rs b/src/scheduler.rs index f1664ae..f564a60 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -75,10 +75,7 @@ impl Scheduler { } } 'next_tick: loop { - let shutdown = { - let r = shutdown.load(Ordering::Relaxed); - r - }; + let shutdown = { shutdown.load(Ordering::Relaxed) }; if shutdown { break 'next_tick; } diff --git a/src/store/metadata_store.rs b/src/store/metadata_store.rs index c6ab02d..f8bac13 100644 --- a/src/store/metadata_store.rs +++ b/src/store/metadata_store.rs @@ -25,4 +25,5 @@ pub trait MetaDataStorage: DataStore + InitStore { ) -> Pin, JobSchedulerError>> + Send>>; } +#[allow(dead_code)] pub trait JobCodeGet: CodeGet> {} diff --git a/src/store/mod.rs b/src/store/mod.rs index 859feee..738f244 100644 --- a/src/store/mod.rs +++ b/src/store/mod.rs @@ -33,6 +33,7 @@ where ) -> Pin> + Send>>; } +#[allow(dead_code)] pub trait CodeGet where CODE: Sized, diff --git a/src/store/notification_store.rs b/src/store/notification_store.rs index 8a4e6b0..720508a 100644 --- a/src/store/notification_store.rs +++ b/src/store/notification_store.rs @@ -33,4 +33,5 @@ pub trait NotificationStore: DataStore + InitStore { ) -> Pin> + Send>>; } +#[allow(dead_code)] pub trait NotificationRunnableCodeGet: CodeGet> {}