Open ryanwalls opened 8 years ago
Where/how do you use currentActivity
?
I have a decider that I use whenever I have a serial list of activities I need to run. It has several custom deciders in it, but it will give you an idea of how I'm using currentActivity
.
var WaitingForActivityDecider = func(currentActivity, nextActivity string,
workflowConfig *config.WorkflowConfig) fsm.Decider {
return fsm.NewComposedDecider(
fsm.OnActivityCompleted(currentActivity, fsm.UpdateState(UpdateStateFromPreviousResult),
fsm.UpdateState(WriteSimulationOutputs),
OnLastActivity(currentActivity, fsm.UpdateState(SetCompletedDatabaseState), fsm.CompleteWorkflow()),
fsm.AddDecision(ScheduleActivityDecisionFunc(nextActivity, workflowConfig)),
fsm.AddDecisions(ScheduleExperimentalActivityDecisionsFunc(nextActivity, workflowConfig)),
fsm.UpdateState(UpdateDatabaseState(workflowConfig)),
fsm.Transition(nextActivity)),
OnActivityFailedWithRecoverableError(currentActivity,
fsm.AddDecision(ScheduleRetryTimer()), fsm.Stay()),
OnAnyTimerFired(fsm.AddDecision(RetryActivityFromTimer), fsm.Stay()),
fsm.OnActivityFailed(currentActivity, fsm.AddDecision(FailWorkflow), fsm.UpdateState(SetErrorDatabaseState)),
fsm.OnWorkflowCancelRequested(fsm.AddDecisions(CancelOutstandingActivities),
fsm.Transition(ActivitiesCancelledStateName)),
fsm.DefaultDecider(),
)
}
I use this decider when I'm setting up my states. e.g.
thermalSolverState := &fsm.FSMState{
Name: thermalSolverStateName,
Decider: fsmadditions.WaitingForActivityDecider(thermalSolverStateName, mechanicsSolverStateName, config.SimulationWorkflow),
}
I have a case where I need to retry a failed activity task, but only if it fails for a specific reason.
Currently, I've solved this with the following code:
IsRecoverableEvent
just returns abool
.Instead of doing it this way, I thought about creating an
OnEvent
function similar toOnData
that took a a new type of predicate function that takes in the context, last event, and state data.Thoughts?