Skip to content

Commit

Permalink
Merge pull request #2750 from lann/factors-redis-trigger
Browse files Browse the repository at this point in the history
Factors redis trigger
  • Loading branch information
rylev authored Aug 23, 2024
2 parents 752939c + 381bd80 commit f246b57
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 33 deletions.
89 changes: 73 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ spin-telemetry = { path = "crates/telemetry", features = [
spin-templates = { path = "crates/templates" }
spin-trigger2 = { path = "crates/trigger2" }
spin-trigger-http2 = { path = "crates/trigger-http2" }
# TODO: spin-trigger-redis = { path = "crates/trigger-redis" }
spin-trigger-redis = { path = "crates/trigger-redis" }

tempfile = "3.8.0"
tokio = { version = "1.23", features = ["full"] }
Expand Down
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ error: the `wasm32-wasi` target is not installed

build_wasm_test_program("core-wasi-test.wasm", "crates/core/tests/core-wasi-test");
// build_wasm_test_program("redis-rust.wasm", "crates/trigger-redis/tests/rust");

// build_wasm_test_program(
// "spin-http-benchmark.wasm",
// "crates/trigger-http/benches/spin-http-benchmark",
Expand Down
2 changes: 1 addition & 1 deletion crates/expressions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl<'a> AsRef<str> for Key<'a> {
}
}

type Result<T> = std::result::Result<T, Error>;
pub type Result<T> = std::result::Result<T, Error>;

/// A variable resolution error.
#[derive(Debug, thiserror::Error)]
Expand Down
12 changes: 11 additions & 1 deletion crates/factor-variables/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub mod spin_cli;
use std::sync::Arc;

use runtime_config::RuntimeConfig;
use spin_expressions::ProviderResolver as ExpressionResolver;
use spin_expressions::{ProviderResolver as ExpressionResolver, Template};
use spin_factors::{
anyhow, ConfigureAppContext, Factor, InitContext, InstanceBuilders, PrepareContext,
RuntimeFactors, SelfInstanceBuilder,
Expand Down Expand Up @@ -70,6 +70,16 @@ pub struct AppState {
expression_resolver: Arc<ExpressionResolver>,
}

impl AppState {
pub async fn resolve_expression(
&self,
expr: impl Into<Box<str>>,
) -> spin_expressions::Result<String> {
let template = Template::new(expr)?;
self.expression_resolver.resolve_template(&template).await
}
}

pub struct InstanceState {
component_id: String,
expression_resolver: Arc<ExpressionResolver>,
Expand Down
4 changes: 4 additions & 0 deletions crates/factors-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ impl<T: RuntimeFactors, U: Send + 'static> FactorsExecutorApp<T, U> {
&self.executor.core_engine
}

pub fn configured_app(&self) -> &ConfiguredApp<T> {
&self.configured_app
}

pub fn app(&self) -> &App {
self.configured_app.app()
}
Expand Down
4 changes: 1 addition & 3 deletions crates/trigger-http2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ impl CliArgs {
}
}

pub(crate) type InstanceState = ();

/// The Spin HTTP trigger.
pub struct HttpTrigger {
/// The address the server should listen on.
Expand All @@ -76,7 +74,7 @@ impl Trigger for HttpTrigger {
const TYPE: &'static str = "http";

type CliArgs = CliArgs;
type InstanceState = InstanceState;
type InstanceState = ();

fn new(cli_args: Self::CliArgs, app: &spin_app::App) -> anyhow::Result<Self> {
Self::new(app, cli_args.address, cli_args.into_tls_config())
Expand Down
24 changes: 24 additions & 0 deletions crates/trigger-redis/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "spin-trigger-redis"
version = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }

[lib]
doctest = false

[dependencies]
anyhow = "1.0"
async-trait = "0.1"
futures = "0.3"
serde = "1.0.188"
spin-factor-variables = { path = "../factor-variables" }
spin-telemetry = { path = "../telemetry" }
spin-trigger2 = { path = "../trigger2" }
spin-world = { path = "../world" }
redis = { version = "0.26.1", features = ["tokio-comp"] }
tracing = { workspace = true }
tokio = { version = "1.39.3", features = ["macros", "rt"] }

[lints]
workspace = true
Loading

0 comments on commit f246b57

Please sign in to comment.