Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: karthik2804 <[email protected]>
  • Loading branch information
karthik2804 committed Mar 26, 2024
1 parent ba740df commit e3f7e63
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 78 deletions.
56 changes: 0 additions & 56 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ spin-app = { git = "https://github.com/fermyon/spin" }
spin-core = { git = "https://github.com/fermyon/spin" }
spin-trigger = { git = "https://github.com/fermyon/spin" }
tokio = { version = "1.23", features = ["full"] }
tokio-cron-scheduler = "0.9.4"
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3.7", features = ["env-filter"] }
wasmtime-wasi = { version = "18.0.1", features = ["tokio"] }
Expand Down
45 changes: 24 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use spin_app::AppComponent;
use spin_core::Engine;
use spin_trigger::TriggerInstancePre;
use spin_trigger::{cli::NoArgs, TriggerAppEngine, TriggerExecutor};

pub(crate) type RuntimeData = ();
pub(crate) type Store = spin_core::Store<RuntimeData>;
type RuntimeData = ();
type Store = spin_core::Store<RuntimeData>;

pub struct CommandTrigger {
engine: TriggerAppEngine<Self>,
Expand Down Expand Up @@ -74,16 +74,19 @@ impl TriggerInstancePre<RuntimeData, CommandTriggerConfig> for CommandInstancePr
component: &AppComponent,
_config: &CommandTriggerConfig,
) -> Result<CommandInstancePre> {
// Attempt to load as a component and fallback to loading a module
if let Ok(comp) = component.load_component(engine).await {
Ok(CommandInstancePre::Component(
engine.instantiate_pre(&comp)?,
))
} else {
let module = component.load_module(engine).await?;
Ok(CommandInstancePre::Module(
engine.module_instantiate_pre(&module)?,
))
// Attempt to load as a module and fallback to loading a component
match component.load_module(engine).await {
Ok(m) => Ok(CommandInstancePre::Module(
engine
.module_instantiate_pre(&m)
.context("Preview1 modules supports only preview1 imports")?,
)),
Err(module_load_err) => match component.load_component(engine).await {
Ok(c) => Ok(CommandInstancePre::Component(engine.instantiate_pre(&c)?)),
Err(component_load_err) => Err(anyhow!("{component_load_err}")
.context(module_load_err)
.context("failed to load component or module")),
},
}
}

Expand Down Expand Up @@ -121,15 +124,15 @@ impl CommandTrigger {
.engine
.prepare_instance_with_store(&component.id, store_builder)
.await?;
if let CommandInstance::Module(instance) = instance {
let start = instance
.get_func(&mut store, "_start")
.context("Expected component to export _start function")?;

let _ = start.call_async(&mut store, &[], &mut []).await?;
} else {
let CommandInstance::Module(instance) = instance else {
unreachable!();
}
};

let start = instance
.get_func(&mut store, "_start")
.context("Expected component to export _start function")?;

let _ = start.call_async(&mut store, &[], &mut []).await?;
}
}

Expand Down

0 comments on commit e3f7e63

Please sign in to comment.