Skip to content

Commit

Permalink
factors: Port redis trigger
Browse files Browse the repository at this point in the history
Signed-off-by: Lann Martin <[email protected]>
  • Loading branch information
lann committed Aug 22, 2024
1 parent afbcfa6 commit eaaf1f0
Show file tree
Hide file tree
Showing 15 changed files with 281 additions and 650 deletions.
81 changes: 58 additions & 23 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 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
16 changes: 5 additions & 11 deletions crates/trigger-redis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ anyhow = "1.0"
async-trait = "0.1"
futures = "0.3"
serde = "1.0.188"
spin-app = { path = "../app" }
spin-common = { path = "../common" }
spin-core = { path = "../core" }
spin-expressions = { path = "../expressions" }
spin-trigger = { path = "../trigger" }
spin-factor-variables = { path = "../factor-variables" }
spin-telemetry = { path = "../telemetry" }
spin-trigger2 = { path = "../trigger2" }
spin-world = { path = "../world" }
redis = { version = "0.21", features = ["tokio-comp"] }
redis = { version = "0.26.1", features = ["tokio-comp"] }
tracing = { workspace = true }
tokio = { version = "1.23", features = ["full"] }
spin-telemetry = { path = "../telemetry" }

[dev-dependencies]
spin-testing = { path = "../testing" }
tokio = { version = "1.39.3", features = ["macros", "rt"] }

[lints]
workspace = true
Loading

0 comments on commit eaaf1f0

Please sign in to comment.