Skip to content

Commit ed08997

Browse files
committed
fix: improved error handling
1 parent 9b92ce6 commit ed08997

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

adapter/cron/src/main.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,24 @@ impl IdentifiableFlow for Time {
6262
};
6363

6464
let expression = format!("* {} {} {} {} {}", minute, hour, dom, month, dow);
65-
let schedule = Schedule::from_str(expression.as_str()).unwrap();
66-
let next = schedule.upcoming(Utc).next().unwrap();
65+
let schedule = match Schedule::from_str(expression.as_str()) {
66+
Ok(s) => s,
67+
Err(e) => {
68+
log::error!(
69+
"Could not create schedule from expression ({}). Reason: {:?}",
70+
expression,
71+
e
72+
);
73+
return false;
74+
}
75+
};
76+
let next = match schedule.upcoming(Utc).next() {
77+
Some(n) => n,
78+
None => {
79+
log::error!("Could not find any upcomming schedules");
80+
return false;
81+
}
82+
};
6783

6884
self.now.year() == next.year()
6985
&& self.now.month() == next.month()
@@ -87,12 +103,12 @@ impl Server<CronConfig> for Cron {
87103

88104
loop {
89105
let now = Utc::now();
90-
log::info!("Schedlued: {:?}", now);
106+
log::info!("Scheduled: {:?}", now);
91107
if let Some(next) = schedule.upcoming(Utc).take(1).next() {
92108
let until_next = next - now;
93109
tokio::time::sleep(until_next.to_std()?).await;
94110

95-
let time = Time { now };
111+
let time = Time { now: next };
96112
match ctx
97113
.adapter_store
98114
.get_possible_flow_match(pattern.to_string(), time)

0 commit comments

Comments
 (0)