mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-16 00:53:47 -05:00
fix: improve error handling when scheduling automatic refresh
This commit is contained in:
@@ -56,13 +56,24 @@ pub async fn serve(port: &u16, ctx: &Context) -> std::io::Result<()> {
|
|||||||
if let Some(interval) = &ctx.config.refresh_interval {
|
if let Some(interval) = &ctx.config.refresh_interval {
|
||||||
scheduler
|
scheduler
|
||||||
.add(
|
.add(
|
||||||
Job::new_async(interval, move |_uuid, _lock| {
|
match Job::new_async(interval, move |_uuid, _lock| {
|
||||||
let data_copy = data_copy.clone();
|
let data_copy = data_copy.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
data_copy.lock().await.refresh().await;
|
data_copy.lock().await.refresh().await;
|
||||||
})
|
})
|
||||||
})
|
}) {
|
||||||
.unwrap(),
|
Ok(job) => job,
|
||||||
|
Err(e) => match e {
|
||||||
|
tokio_cron_scheduler::JobSchedulerError::ParseSchedule => error!(
|
||||||
|
"Failed to parse cron schedule: {}. Please ensure it is valid!",
|
||||||
|
interval
|
||||||
|
),
|
||||||
|
e => error!(
|
||||||
|
"An unexpected error occured while scheduling automatic refresh: {}",
|
||||||
|
e
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user