Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update trigger timer to multi-friendly lockfile layout #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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