Skip to content

Commit f246b57

Browse files
authored
Merge pull request #2750 from lann/factors-redis-trigger
Factors redis trigger
2 parents 752939c + 381bd80 commit f246b57

File tree

12 files changed

+352
-33
lines changed

12 files changed

+352
-33
lines changed

Cargo.lock

Lines changed: 73 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ spin-telemetry = { path = "crates/telemetry", features = [
6464
spin-templates = { path = "crates/templates" }
6565
spin-trigger2 = { path = "crates/trigger2" }
6666
spin-trigger-http2 = { path = "crates/trigger-http2" }
67-
# TODO: spin-trigger-redis = { path = "crates/trigger-redis" }
67+
spin-trigger-redis = { path = "crates/trigger-redis" }
6868

6969
tempfile = "3.8.0"
7070
tokio = { version = "1.23", features = ["full"] }

build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ error: the `wasm32-wasi` target is not installed
6969

7070
build_wasm_test_program("core-wasi-test.wasm", "crates/core/tests/core-wasi-test");
7171
// build_wasm_test_program("redis-rust.wasm", "crates/trigger-redis/tests/rust");
72-
7372
// build_wasm_test_program(
7473
// "spin-http-benchmark.wasm",
7574
// "crates/trigger-http/benches/spin-http-benchmark",

crates/expressions/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl<'a> AsRef<str> for Key<'a> {
267267
}
268268
}
269269

270-
type Result<T> = std::result::Result<T, Error>;
270+
pub type Result<T> = std::result::Result<T, Error>;
271271

272272
/// A variable resolution error.
273273
#[derive(Debug, thiserror::Error)]

crates/factor-variables/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod spin_cli;
55
use std::sync::Arc;
66

77
use runtime_config::RuntimeConfig;
8-
use spin_expressions::ProviderResolver as ExpressionResolver;
8+
use spin_expressions::{ProviderResolver as ExpressionResolver, Template};
99
use spin_factors::{
1010
anyhow, ConfigureAppContext, Factor, InitContext, InstanceBuilders, PrepareContext,
1111
RuntimeFactors, SelfInstanceBuilder,
@@ -70,6 +70,16 @@ pub struct AppState {
7070
expression_resolver: Arc<ExpressionResolver>,
7171
}
7272

73+
impl AppState {
74+
pub async fn resolve_expression(
75+
&self,
76+
expr: impl Into<Box<str>>,
77+
) -> spin_expressions::Result<String> {
78+
let template = Template::new(expr)?;
79+
self.expression_resolver.resolve_template(&template).await
80+
}
81+
}
82+
7383
pub struct InstanceState {
7484
component_id: String,
7585
expression_resolver: Arc<ExpressionResolver>,

crates/factors-executor/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ impl<T: RuntimeFactors, U: Send + 'static> FactorsExecutorApp<T, U> {
115115
&self.executor.core_engine
116116
}
117117

118+
pub fn configured_app(&self) -> &ConfiguredApp<T> {
119+
&self.configured_app
120+
}
121+
118122
pub fn app(&self) -> &App {
119123
self.configured_app.app()
120124
}

crates/trigger-http2/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ impl CliArgs {
6060
}
6161
}
6262

63-
pub(crate) type InstanceState = ();
64-
6563
/// The Spin HTTP trigger.
6664
pub struct HttpTrigger {
6765
/// The address the server should listen on.
@@ -76,7 +74,7 @@ impl Trigger for HttpTrigger {
7674
const TYPE: &'static str = "http";
7775

7876
type CliArgs = CliArgs;
79-
type InstanceState = InstanceState;
77+
type InstanceState = ();
8078

8179
fn new(cli_args: Self::CliArgs, app: &spin_app::App) -> anyhow::Result<Self> {
8280
Self::new(app, cli_args.address, cli_args.into_tls_config())

crates/trigger-redis/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "spin-trigger-redis"
3+
version = { workspace = true }
4+
authors = { workspace = true }
5+
edition = { workspace = true }
6+
7+
[lib]
8+
doctest = false
9+
10+
[dependencies]
11+
anyhow = "1.0"
12+
async-trait = "0.1"
13+
futures = "0.3"
14+
serde = "1.0.188"
15+
spin-factor-variables = { path = "../factor-variables" }
16+
spin-telemetry = { path = "../telemetry" }
17+
spin-trigger2 = { path = "../trigger2" }
18+
spin-world = { path = "../world" }
19+
redis = { version = "0.26.1", features = ["tokio-comp"] }
20+
tracing = { workspace = true }
21+
tokio = { version = "1.39.3", features = ["macros", "rt"] }
22+
23+
[lints]
24+
workspace = true

0 commit comments

Comments
 (0)