Skip to content

Commit

Permalink
Merge pull request #1 from itowlson/fix-trigger-timer
Browse files Browse the repository at this point in the history
Update trigger timer to multi-friendly lockfile layout
  • Loading branch information
carlokok authored Jan 10, 2024
2 parents e1176f4 + b11ad73 commit 40dd64e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions examples/spin-timer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ pub struct TimerTrigger {
component_timings: HashMap<String, u64>,
}

// Application settings (raw serialization format)
// Picks out the timer entry from the application-level trigger settings
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
struct TriggerMetadataParent {
timer: Option<TriggerMetadata>,
}

// Application-level settings (raw serialization format)
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
struct TriggerMetadata {
r#type: String,
speedup: Option<u64>,
}

Expand All @@ -45,7 +50,7 @@ pub struct TimerTriggerConfig {
interval_secs: u64,
}

const TRIGGER_METADATA_KEY: MetadataKey<TriggerMetadata> = MetadataKey::new("triggers");
const TRIGGER_METADATA_KEY: MetadataKey<TriggerMetadataParent> = MetadataKey::new("triggers");

#[async_trait]
impl TriggerExecutor for TimerTrigger {
Expand All @@ -61,6 +66,8 @@ impl TriggerExecutor for TimerTrigger {
let speedup = engine
.app()
.require_metadata(TRIGGER_METADATA_KEY)?
.timer
.unwrap_or_default()
.speedup
.unwrap_or(1);

Expand Down
2 changes: 1 addition & 1 deletion examples/spin-timer/trigger-timer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Run Spin components at timed intervals",
"homepage": "https://github.com/fermyon/spin/tree/main/examples/spin-timer",
"version": "0.1.0",
"spinCompatibility": ">=2.0",
"spinCompatibility": ">=2.2",
"license": "Apache-2.0",
"packages": [
{
Expand Down

0 comments on commit 40dd64e

Please sign in to comment.