Skip to content

Commit

Permalink
feat: on cron event handles response from module
Browse files Browse the repository at this point in the history
  • Loading branch information
saibatizoku committed Mar 27, 2024
1 parent 85867c3 commit b02a1df
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions hermes/bin/src/runtime_extensions/hermes/cron/event.rs
Expand Up @@ -3,6 +3,7 @@
use chrono::Utc;
use saffron::Cron;

use super::state::cron_queue_rm;
use crate::{
event::HermesEventPayload, runtime_extensions::bindings::hermes::cron::api::CronTagged,
};
Expand All @@ -25,12 +26,17 @@ impl HermesEventPayload for OnCronEvent {
}

fn execute(&self, module: &mut crate::wasm::module::ModuleInstance) -> anyhow::Result<()> {
// TODO (@stevenj): https://github.com/input-output-hk/hermes/issues/93
let _res: bool = module.instance.hermes_cron_event().call_on_cron(
let res: bool = module.instance.hermes_cron_event().call_on_cron(
&mut module.store,
&self.tag,
self.last,
)?;
// if the response is `false`, check if the event would
// re-trigger, if so, remove it.
if !res && !self.last {
let app_name = module.store.data().app_name();
cron_queue_rm(&app_name.0, self.tag.clone());
}
Ok(())
}
}
Expand Down

0 comments on commit b02a1df

Please sign in to comment.