|
1 | 1 | use std::collections::HashMap;
|
2 | 2 |
|
| 3 | +use anyhow::Context; |
3 | 4 | use clap::Args;
|
4 | 5 | use serde::{Deserialize, Serialize};
|
5 |
| -use spin_app::MetadataKey; |
6 |
| -use spin_core::async_trait; |
7 |
| -use spin_trigger::{EitherInstance, TriggerAppEngine, TriggerExecutor}; |
| 6 | +use spin_app::{AppComponent, MetadataKey}; |
| 7 | +use spin_core::{async_trait, Engine, Instance, InstancePre, Store}; |
| 8 | +use spin_trigger::{TriggerAppEngine, TriggerExecutor}; |
8 | 9 |
|
9 | 10 | wasmtime::component::bindgen!({
|
10 | 11 | path: ".",
|
@@ -62,6 +63,10 @@ impl TriggerExecutor for TimerTrigger {
|
62 | 63 |
|
63 | 64 | type RunConfig = CliArgs;
|
64 | 65 |
|
| 66 | + type InstancePre = InstancePre<RuntimeData>; |
| 67 | + |
| 68 | + type Instance = Instance; |
| 69 | + |
65 | 70 | async fn new(engine: spin_trigger::TriggerAppEngine<Self>) -> anyhow::Result<Self> {
|
66 | 71 | let speedup = engine
|
67 | 72 | .app()
|
@@ -113,15 +118,30 @@ impl TriggerExecutor for TimerTrigger {
|
113 | 118 | }
|
114 | 119 | Ok(())
|
115 | 120 | }
|
| 121 | + |
| 122 | + async fn instantiate_pre( |
| 123 | + engine: &Engine<RuntimeData>, |
| 124 | + component: &AppComponent, |
| 125 | + _config: &TimerTriggerConfig, |
| 126 | + ) -> anyhow::Result<InstancePre<RuntimeData>> { |
| 127 | + let comp = component.load_component(engine).await?; |
| 128 | + Ok(engine |
| 129 | + .instantiate_pre(&comp) |
| 130 | + .with_context(|| format!("Failed to instantiate component '{}'", component.id()))?) |
| 131 | + } |
| 132 | + |
| 133 | + async fn instantiate( |
| 134 | + store: &mut Store<RuntimeData>, |
| 135 | + pre: &Self::InstancePre, |
| 136 | + ) -> anyhow::Result<Instance> { |
| 137 | + pre.instantiate_async(store).await |
| 138 | + } |
116 | 139 | }
|
117 | 140 |
|
118 | 141 | impl TimerTrigger {
|
119 | 142 | async fn handle_timer_event(&self, component_id: &str) -> anyhow::Result<()> {
|
120 | 143 | // Load the guest...
|
121 | 144 | let (instance, mut store) = self.engine.prepare_instance(component_id).await?;
|
122 |
| - let EitherInstance::Component(instance) = instance else { |
123 |
| - unreachable!() |
124 |
| - }; |
125 | 145 | let instance = SpinTimer::new(&mut store, &instance)?;
|
126 | 146 | // ...and call the entry point
|
127 | 147 | instance.call_handle_timer_request(&mut store).await
|
|
0 commit comments