Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use state machines and add missing From trait implementations #17

Merged
merged 2 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
# sdk-core is a library we allow consumers pin specific versions.
Cargo.lock

/.idea/
/.idea/
*.iml
14 changes: 14 additions & 0 deletions src/machines/activity_state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ fsm! {

#[derive(thiserror::Error, Debug)]
pub enum ActivityMachineError {}

pub enum ActivityCommand {}

#[derive(Default)]
pub struct Created {}

impl Created {
pub fn on_schedule(self) -> ActivityMachineTransition {
// would add command here
Expand All @@ -64,6 +66,7 @@ impl Created {

#[derive(Default)]
pub struct ScheduleCommandCreated {}

impl ScheduleCommandCreated {
pub fn on_activity_task_scheduled(self) -> ActivityMachineTransition {
// set initial command event id
Expand All @@ -78,6 +81,7 @@ impl ScheduleCommandCreated {

#[derive(Default)]
pub struct ScheduledEventRecorded {}

impl ScheduledEventRecorded {
pub fn on_task_started(self) -> ActivityMachineTransition {
// setStartedCommandEventId
Expand All @@ -95,6 +99,7 @@ impl ScheduledEventRecorded {

#[derive(Default)]
pub struct Started {}

impl Started {
pub fn on_activity_task_completed(self) -> ActivityMachineTransition {
// notify_completed
Expand All @@ -116,6 +121,7 @@ impl Started {

#[derive(Default)]
pub struct ScheduledActivityCancelCommandCreated {}

impl ScheduledActivityCancelCommandCreated {
pub fn on_command_request_cancel_activity_task(self) -> ActivityMachineTransition {
// notifyCanceledIfTryCancel
Expand All @@ -125,6 +131,7 @@ impl ScheduledActivityCancelCommandCreated {

#[derive(Default)]
pub struct ScheduledActivityCancelEventRecorded {}

impl ScheduledActivityCancelEventRecorded {
pub fn on_activity_task_canceled(self) -> ActivityMachineTransition {
// notify_canceled
Expand All @@ -135,6 +142,7 @@ impl ScheduledActivityCancelEventRecorded {
ActivityMachineTransition::default::<Canceled>()
}
}

impl From<ScheduledActivityCancelCommandCreated> for ScheduledActivityCancelEventRecorded {
fn from(_: ScheduledActivityCancelCommandCreated) -> Self {
Self::default()
Expand All @@ -143,6 +151,7 @@ impl From<ScheduledActivityCancelCommandCreated> for ScheduledActivityCancelEven

#[derive(Default)]
pub struct StartedActivityCancelCommandCreated {}

impl StartedActivityCancelCommandCreated {
pub fn on_activity_task_cancel_requested(self) -> ActivityMachineTransition {
// notifyCanceledIfTryCancel
Expand All @@ -152,6 +161,7 @@ impl StartedActivityCancelCommandCreated {

#[derive(Default)]
pub struct StartedActivityCancelEventRecorded {}

impl StartedActivityCancelEventRecorded {
pub fn on_activity_task_completed(self) -> ActivityMachineTransition {
// notify_completed
Expand All @@ -170,6 +180,7 @@ impl StartedActivityCancelEventRecorded {
ActivityMachineTransition::default::<Failed>()
}
}

impl From<ScheduledActivityCancelEventRecorded> for StartedActivityCancelEventRecorded {
fn from(_: ScheduledActivityCancelEventRecorded) -> Self {
Self::default()
Expand All @@ -178,10 +189,13 @@ impl From<ScheduledActivityCancelEventRecorded> for StartedActivityCancelEventRe

#[derive(Default)]
pub struct Completed {}

#[derive(Default)]
pub struct Failed {}

#[derive(Default)]
pub struct TimedOut {}

#[derive(Default)]
pub struct Canceled {}

Expand Down
39 changes: 28 additions & 11 deletions src/machines/cancel_external_state_machine.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
use rustfsm::{fsm, TransitionResult};

fsm! {
CancelExternalMachine, CancelExternalCommand, CancelExternalMachineError
CancelExternalMachine, CancelExternalCommand, CancelExternalMachineError

Created --(Schedule, on_schedule) --> RequestCancelExternalCommandCreated;
Created --(Schedule, on_schedule) --> RequestCancelExternalCommandCreated;

RequestCancelExternalCommandCreated --(CommandRequestCancelExternalWorkflowExecution) --> RequestCancelExternalCommandCreated;
RequestCancelExternalCommandCreated --(RequestCancelExternalWorkflowExecutionInitiated, on_request_cancel_external_workflow_execution_initiated) --> RequestCancelExternalCommandRecorded;
RequestCancelExternalCommandCreated --(CommandRequestCancelExternalWorkflowExecution) --> RequestCancelExternalCommandCreated;
RequestCancelExternalCommandCreated --(RequestCancelExternalWorkflowExecutionInitiated, on_request_cancel_external_workflow_execution_initiated) --> RequestCancelExternalCommandRecorded;

RequestCancelExternalCommandRecorded --(ExternalWorkflowExecutionCancelRequested, on_external_workflow_execution_cancel_requested) --> CancelRequested;
RequestCancelExternalCommandRecorded --(RequestCancelExternalWorkflowExecutionFailed, on_request_cancel_external_workflow_execution_failed) --> RequestCancelFailed;
RequestCancelExternalCommandRecorded --(ExternalWorkflowExecutionCancelRequested, on_external_workflow_execution_cancel_requested) --> CancelRequested;
RequestCancelExternalCommandRecorded --(RequestCancelExternalWorkflowExecutionFailed, on_request_cancel_external_workflow_execution_failed) --> RequestCancelFailed;
}

#[derive(thiserror::Error, Debug)]
pub enum CancelExternalMachineError {}

pub enum CancelExternalCommand {}

#[derive(Default)]
pub struct CancelRequested {}

#[derive(Default)]
pub struct Created {}

impl Created {
pub fn on_schedule(self) -> CancelExternalMachineTransition { unimplemented!() }
pub fn on_schedule(self) -> CancelExternalMachineTransition {
unimplemented!()
}
}

#[derive(Default)]
pub struct RequestCancelExternalCommandCreated {}

impl RequestCancelExternalCommandCreated {
pub fn on_request_cancel_external_workflow_execution_initiated(self) -> CancelExternalMachineTransition { unimplemented!() }
pub fn on_request_cancel_external_workflow_execution_initiated(
self,
) -> CancelExternalMachineTransition {
unimplemented!()
}
}

#[derive(Default)]
pub struct RequestCancelExternalCommandRecorded {}

impl RequestCancelExternalCommandRecorded {
pub fn on_external_workflow_execution_cancel_requested(self) -> CancelExternalMachineTransition { unimplemented!() }
pub fn on_request_cancel_external_workflow_execution_failed(self) -> CancelExternalMachineTransition { unimplemented!() }
pub fn on_external_workflow_execution_cancel_requested(
self,
) -> CancelExternalMachineTransition {
unimplemented!()
}
pub fn on_request_cancel_external_workflow_execution_failed(
self,
) -> CancelExternalMachineTransition {
unimplemented!()
}
}

#[derive(Default)]
pub struct RequestCancelFailed {}

20 changes: 13 additions & 7 deletions src/machines/cancel_workflow_state_machine.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
use rustfsm::{fsm, TransitionResult};

fsm! {
CancelWorkflowMachine, CancelWorkflowCommand, CancelWorkflowMachineError
CancelWorkflowMachine, CancelWorkflowCommand, CancelWorkflowMachineError

CancelWorkflowCommandCreated --(CommandCancelWorkflowExecution) --> CancelWorkflowCommandCreated;
CancelWorkflowCommandCreated --(WorkflowExecutionCanceled, on_workflow_execution_canceled) --> CancelWorkflowCommandRecorded;
CancelWorkflowCommandCreated --(CommandCancelWorkflowExecution) --> CancelWorkflowCommandCreated;
CancelWorkflowCommandCreated --(WorkflowExecutionCanceled, on_workflow_execution_canceled) --> CancelWorkflowCommandRecorded;

Created --(Schedule, on_schedule) --> CancelWorkflowCommandCreated;
Created --(Schedule, on_schedule) --> CancelWorkflowCommandCreated;
}

#[derive(thiserror::Error, Debug)]
pub enum CancelWorkflowMachineError {}

pub enum CancelWorkflowCommand {}

#[derive(Default)]
pub struct CancelWorkflowCommandCreated {}

impl CancelWorkflowCommandCreated {
pub fn on_workflow_execution_canceled(self) -> CancelWorkflowMachineTransition { unimplemented!() }
pub fn on_workflow_execution_canceled(self) -> CancelWorkflowMachineTransition {
unimplemented!()
}
}

#[derive(Default)]
pub struct CancelWorkflowCommandRecorded {}

#[derive(Default)]
pub struct Created {}

impl Created {
pub fn on_schedule(self) -> CancelWorkflowMachineTransition { unimplemented!() }
pub fn on_schedule(self) -> CancelWorkflowMachineTransition {
unimplemented!()
}
}

70 changes: 47 additions & 23 deletions src/machines/child_workflow_state_machine.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
use rustfsm::{fsm, TransitionResult};

fsm! {
ChildWorkflowMachine, ChildWorkflowCommand, ChildWorkflowMachineError
ChildWorkflowMachine, ChildWorkflowCommand, ChildWorkflowMachineError

Created --(Schedule, on_schedule) --> StartCommandCreated;
Created --(Schedule, on_schedule) --> StartCommandCreated;

Started --(ChildWorkflowExecutionCompleted, on_child_workflow_execution_completed) --> Completed;
Started --(ChildWorkflowExecutionFailed, on_child_workflow_execution_failed) --> Failed;
Started --(ChildWorkflowExecutionTimedOut, on_child_workflow_execution_timed_out) --> TimedOut;
Started --(ChildWorkflowExecutionCanceled, on_child_workflow_execution_canceled) --> Canceled;
Started --(ChildWorkflowExecutionTerminated, on_child_workflow_execution_terminated) --> Terminated;
Started --(ChildWorkflowExecutionCompleted, on_child_workflow_execution_completed) --> Completed;
Started --(ChildWorkflowExecutionFailed, on_child_workflow_execution_failed) --> Failed;
Started --(ChildWorkflowExecutionTimedOut, on_child_workflow_execution_timed_out) --> TimedOut;
Started --(ChildWorkflowExecutionCanceled, on_child_workflow_execution_canceled) --> Canceled;
Started --(ChildWorkflowExecutionTerminated, on_child_workflow_execution_terminated) --> Terminated;

StartCommandCreated --(CommandStartChildWorkflowExecution) --> StartCommandCreated;
StartCommandCreated --(StartChildWorkflowExecutionInitiated, on_start_child_workflow_execution_initiated) --> StartEventRecorded;
StartCommandCreated --(Cancel, on_cancel) --> Canceled;
StartCommandCreated --(CommandStartChildWorkflowExecution) --> StartCommandCreated;
StartCommandCreated --(StartChildWorkflowExecutionInitiated, on_start_child_workflow_execution_initiated) --> StartEventRecorded;
StartCommandCreated --(Cancel, on_cancel) --> Canceled;

StartEventRecorded --(ChildWorkflowExecutionStarted, on_child_workflow_execution_started) --> Started;
StartEventRecorded --(StartChildWorkflowExecutionFailed, on_start_child_workflow_execution_failed) --> StartFailed;
StartEventRecorded --(ChildWorkflowExecutionStarted, on_child_workflow_execution_started) --> Started;
StartEventRecorded --(StartChildWorkflowExecutionFailed, on_start_child_workflow_execution_failed) --> StartFailed;
}

#[derive(thiserror::Error, Debug)]
pub enum ChildWorkflowMachineError {}

pub enum ChildWorkflowCommand {}

#[derive(Default)]
Expand All @@ -31,43 +32,66 @@ pub struct Completed {}

#[derive(Default)]
pub struct Created {}

impl Created {
pub fn on_schedule(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_schedule(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
}

#[derive(Default)]
pub struct Failed {}

#[derive(Default)]
pub struct StartCommandCreated {}

impl StartCommandCreated {
pub fn on_start_child_workflow_execution_initiated(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_cancel(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_start_child_workflow_execution_initiated(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
pub fn on_cancel(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
}

#[derive(Default)]
pub struct StartEventRecorded {}

impl StartEventRecorded {
pub fn on_child_workflow_execution_started(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_start_child_workflow_execution_failed(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_child_workflow_execution_started(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
pub fn on_start_child_workflow_execution_failed(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
}

#[derive(Default)]
pub struct StartFailed {}

#[derive(Default)]
pub struct Started {}

impl Started {
pub fn on_child_workflow_execution_completed(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_child_workflow_execution_failed(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_child_workflow_execution_timed_out(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_child_workflow_execution_canceled(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_child_workflow_execution_terminated(self) -> ChildWorkflowMachineTransition { unimplemented!() }
pub fn on_child_workflow_execution_completed(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
pub fn on_child_workflow_execution_failed(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
pub fn on_child_workflow_execution_timed_out(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
pub fn on_child_workflow_execution_canceled(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
pub fn on_child_workflow_execution_terminated(self) -> ChildWorkflowMachineTransition {
unimplemented!()
}
}

#[derive(Default)]
pub struct Terminated {}

#[derive(Default)]
pub struct TimedOut {}

20 changes: 13 additions & 7 deletions src/machines/complete_workflow_state_machine.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
use rustfsm::{fsm, TransitionResult};

fsm! {
CompleteWorkflowMachine, CompleteWorkflowCommand, CompleteWorkflowMachineError
CompleteWorkflowMachine, CompleteWorkflowCommand, CompleteWorkflowMachineError

CompleteWorkflowCommandCreated --(CommandCompleteWorkflowExecution) --> CompleteWorkflowCommandCreated;
CompleteWorkflowCommandCreated --(WorkflowExecutionCompleted, on_workflow_execution_completed) --> CompleteWorkflowCommandRecorded;
CompleteWorkflowCommandCreated --(CommandCompleteWorkflowExecution) --> CompleteWorkflowCommandCreated;
CompleteWorkflowCommandCreated --(WorkflowExecutionCompleted, on_workflow_execution_completed) --> CompleteWorkflowCommandRecorded;

Created --(Schedule, on_schedule) --> CompleteWorkflowCommandCreated;
Created --(Schedule, on_schedule) --> CompleteWorkflowCommandCreated;
}

#[derive(thiserror::Error, Debug)]
pub enum CompleteWorkflowMachineError {}

pub enum CompleteWorkflowCommand {}

#[derive(Default)]
pub struct CompleteWorkflowCommandCreated {}

impl CompleteWorkflowCommandCreated {
pub fn on_workflow_execution_completed(self) -> CompleteWorkflowMachineTransition { unimplemented!() }
pub fn on_workflow_execution_completed(self) -> CompleteWorkflowMachineTransition {
unimplemented!()
}
}

#[derive(Default)]
pub struct CompleteWorkflowCommandRecorded {}

#[derive(Default)]
pub struct Created {}

impl Created {
pub fn on_schedule(self) -> CompleteWorkflowMachineTransition { unimplemented!() }
pub fn on_schedule(self) -> CompleteWorkflowMachineTransition {
unimplemented!()
}
}

Loading