feat(wfe-core): add models, traits, and error types
Core domain models: WorkflowInstance, ExecutionPointer, WorkflowDefinition, WorkflowStep, Event, EventSubscription, ScheduledCommand, ExecutionError, LifecycleEvent, PollEndpointConfig. All serde-serializable. Provider traits: PersistenceProvider (composite of WorkflowRepository, EventRepository, SubscriptionRepository, ScheduledCommandRepository), DistributedLockProvider, QueueProvider, SearchIndex, LifecyclePublisher, WorkflowMiddleware, StepMiddleware, WorkflowRegistry. StepBody trait with StepExecutionContext for workflow step implementations. WorkflowData marker trait (blanket impl for Serialize + DeserializeOwned).
This commit is contained in:
73
wfe-core/src/models/status.rs
Normal file
73
wfe-core/src/models/status.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum WorkflowStatus {
|
||||
#[default]
|
||||
Runnable,
|
||||
Suspended,
|
||||
Complete,
|
||||
Terminated,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum PointerStatus {
|
||||
#[default]
|
||||
Pending,
|
||||
Running,
|
||||
Complete,
|
||||
Sleeping,
|
||||
WaitingForEvent,
|
||||
Failed,
|
||||
Compensated,
|
||||
Cancelled,
|
||||
PendingPredecessor,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn workflow_status_default_is_runnable() {
|
||||
assert_eq!(WorkflowStatus::default(), WorkflowStatus::Runnable);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pointer_status_default_is_pending() {
|
||||
assert_eq!(PointerStatus::default(), PointerStatus::Pending);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn workflow_status_serde_round_trip() {
|
||||
for status in [
|
||||
WorkflowStatus::Runnable,
|
||||
WorkflowStatus::Suspended,
|
||||
WorkflowStatus::Complete,
|
||||
WorkflowStatus::Terminated,
|
||||
] {
|
||||
let json = serde_json::to_string(&status).unwrap();
|
||||
let deserialized: WorkflowStatus = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(status, deserialized);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pointer_status_serde_round_trip() {
|
||||
for status in [
|
||||
PointerStatus::Pending,
|
||||
PointerStatus::Running,
|
||||
PointerStatus::Complete,
|
||||
PointerStatus::Sleeping,
|
||||
PointerStatus::WaitingForEvent,
|
||||
PointerStatus::Failed,
|
||||
PointerStatus::Compensated,
|
||||
PointerStatus::Cancelled,
|
||||
PointerStatus::PendingPredecessor,
|
||||
] {
|
||||
let json = serde_json::to_string(&status).unwrap();
|
||||
let deserialized: PointerStatus = serde_json::from_str(&json).unwrap();
|
||||
assert_eq!(status, deserialized);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user