feat(wfe-core): add ServiceDefinition types and ServiceProvider trait

This commit is contained in:
2026-04-06 17:59:38 +01:00
parent 22d3f569df
commit affcf1bca8
5 changed files with 323 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
pub mod lifecycle;
pub mod lock;
pub mod service;
pub mod log_sink;
pub mod middleware;
pub mod persistence;
@@ -19,4 +20,5 @@ pub use persistence::{
pub use queue::QueueProvider;
pub use registry::WorkflowRegistry;
pub use search::{Page, SearchFilter, SearchIndex, WorkflowSearchResult};
pub use service::ServiceProvider;
pub use step::{HostContext, StepBody, StepExecutionContext, WorkflowData};

View File

@@ -0,0 +1,31 @@
use async_trait::async_trait;
use crate::models::service::{ServiceDefinition, ServiceEndpoint};
/// Provides infrastructure services (databases, caches, etc.) for workflows.
///
/// Implementations handle provisioning, readiness checking, and teardown
/// of services on a specific platform (Kubernetes, containerd, etc.).
#[async_trait]
pub trait ServiceProvider: Send + Sync {
/// Check if this provider can provision the given services.
///
/// Returns false if any service cannot be handled by this provider.
fn can_provision(&self, services: &[ServiceDefinition]) -> bool;
/// Provision all services for a workflow.
///
/// Creates the service containers/pods, waits for them to be ready,
/// and returns endpoint information for each service.
async fn provision(
&self,
workflow_id: &str,
services: &[ServiceDefinition],
) -> crate::Result<Vec<ServiceEndpoint>>;
/// Tear down all services for a workflow.
///
/// Called on workflow completion, failure, or termination.
/// Should be idempotent -- safe to call multiple times.
async fn teardown(&self, workflow_id: &str) -> crate::Result<()>;
}