Skip to content

Commit

Permalink
fix: update Host implementation to use global static state
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed Mar 6, 2024
1 parent e5cd107 commit dfde310
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions hermes/bin/src/runtime_extensions/hermes/cron/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ impl Host for HermesState {
/// this function. This could be useful where a retriggering crontab event is desired
/// to be stopped, but ONLY after it has triggered once more.
fn add(&mut self, entry: CronTagged, retrigger: bool) -> wasmtime::Result<bool> {
if let Ok(state) = CRON_INTERNAL_STATE.lock() {
Ok(state.add_crontab(self.ctx.app_name(), entry, retrigger))
} else {
Ok(false)
}
Ok(CRON_INTERNAL_STATE.add_crontab(self.ctx.app_name(), entry, retrigger))
}

/// # Schedule A Single cron event after a fixed delay.
Expand All @@ -66,11 +62,7 @@ impl Host for HermesState {
/// Listing the crontabs after this call will list the delay in addition to all other
/// crontab entries.
fn delay(&mut self, duration: Instant, tag: CronEventTag) -> wasmtime::Result<bool> {
if let Ok(state) = CRON_INTERNAL_STATE.lock() {
state.delay_crontab(self.ctx.app_name(), duration, tag)
} else {
Ok(false)
}
CRON_INTERNAL_STATE.delay_crontab(self.ctx.app_name(), duration, tag)
}

/// # List currently active cron schedule.
Expand All @@ -91,11 +83,7 @@ impl Host for HermesState {
/// - `0` - `cron-tagged` - The Tagged crontab event.
/// - `1` - `bool` - The state of the retrigger flag.
fn ls(&mut self, tag: Option<CronEventTag>) -> wasmtime::Result<Vec<(CronTagged, bool)>> {
if let Ok(state) = CRON_INTERNAL_STATE.lock() {
Ok(state.ls_crontabs(self.ctx.app_name(), tag))
} else {
Ok(vec![])
}
Ok(CRON_INTERNAL_STATE.ls_crontabs(self.ctx.app_name(), tag))
}

/// # Remove the requested crontab.
Expand All @@ -112,11 +100,7 @@ impl Host for HermesState {
/// - `true`: The requested crontab was deleted and will not trigger.
/// - `false`: The requested crontab does not exist.
fn rm(&mut self, entry: CronTagged) -> wasmtime::Result<bool> {
if let Ok(state) = CRON_INTERNAL_STATE.lock() {
Ok(state.rm_crontab(self.ctx.app_name(), &entry))
} else {
Ok(false)
}
Ok(CRON_INTERNAL_STATE.rm_crontab(self.ctx.app_name(), entry))
}

/// # Make a crontab entry from individual time values.
Expand Down

0 comments on commit dfde310

Please sign in to comment.