Package io.nflow.engine.workflow.curated
Class CronWorkflow
java.lang.Object
io.nflow.engine.model.ModelObject
io.nflow.engine.workflow.definition.WorkflowDefinition
io.nflow.engine.workflow.curated.CronWorkflow
- Direct Known Subclasses:
MaintenanceWorkflow
Workflow that wakes up periodically to execute a task.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final WorkflowStatestatic final WorkflowStatestatic final WorkflowStatestatic final WorkflowStatestatic final WorkflowStateStates of cron workflow.static final StringName of the state variable that stores schedule in cron syntax.static final WorkflowStateFields inherited from class io.nflow.engine.workflow.definition.WorkflowDefinition
allowedTransitions, failureTransitions -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCronWorkflow(String type) Extend cron workflow definition.protectedCronWorkflow(String type, WorkflowSettings settings) Extend cron workflow definition with customized workflow settings. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.joda.time.DateTimegetNextActivationTime(StateExecution execution, String cron) Calculates next activation time based on cron state variable.handleFailure(StateExecution execution) Tries to handle failures by callinghandleFailureImpl(io.nflow.engine.workflow.definition.StateExecution).protected booleanhandleFailureImpl(StateExecution execution) Logs an error and continues.schedule(StateExecution execution, String cron) Determines the next execution time for the doWork state by callinggetNextActivationTime(io.nflow.engine.workflow.definition.StateExecution, java.lang.String).waitForWorkToFinish(StateExecution execution) CallswaitForWorkToFinishImpl(io.nflow.engine.workflow.definition.StateExecution)to check if this instance should wait for work to finish or move to schedule state.protected org.joda.time.DateTimewaitForWorkToFinishImpl(StateExecution execution) Returns null to move to schedule state immediately if there are no incomplete child workflows, or current time plus 1 hour to check again later.Methods inherited from class io.nflow.engine.workflow.definition.WorkflowDefinition
getAllowedTransitions, getDescription, getErrorState, getFailureTransitions, getInitialState, getMethod, getMethod, getName, getSettings, getState, getStates, getSupportedSignals, getType, isAllowedNextAction, isStartState, permit, permit, registerState, setDescription, setNameMethods inherited from class io.nflow.engine.model.ModelObject
equals, hashCode, toString
-
Field Details
-
VAR_SCHEDULE
Name of the state variable that stores schedule in cron syntax.- See Also:
-
SCHEDULE
States of cron workflow. -
DO_WORK
-
WAIT_FOR_WORK_TO_FINISH
-
HANDLE_FAILURE
-
DISABLED
-
FAILED
-
-
Constructor Details
-
CronWorkflow
Extend cron workflow definition with customized workflow settings. It is recommended to enable the workflow state and action history cleanup. Extending class must implement the 'doWork` state method. For example:public NextAction doWork(StateExecution execution) { // do the work here return NextAction.moveToState(schedule, "Work done"); }- Parameters:
type- The type of the workflow.settings- The workflow settings.
-
CronWorkflow
Extend cron workflow definition. Uses workflow settings that enable automatic workflow state and action history cleanup (delete history older than 45 days, run cleanup once per day). Extending class must implement the 'doWork` state method. For example:public NextAction doWork(StateExecution execution) { // do the work here if (rescheduleImmediately) { return NextAction.moveToState(schedule, "Work done"); } return NextAction.moveToStateAfter(waitForWorkToFinish, DateTime.now().plusHours(hoursToWait), "Waiting for work to finish"); }- Parameters:
type- The type of the workflow.
-
-
Method Details
-
schedule
Determines the next execution time for the doWork state by callinggetNextActivationTime(io.nflow.engine.workflow.definition.StateExecution, java.lang.String).- Parameters:
execution- The workflow execution context.cron- The cron state variable.- Returns:
- Action to go to doWork state at scheduled time.
-
getNextActivationTime
Calculates next activation time based on cron state variable. Override for custom scheduling.- Parameters:
execution- The workflow execution context.cron- The cron schedule.- Returns:
- The next activation time.
-
handleFailure
Tries to handle failures by callinghandleFailureImpl(io.nflow.engine.workflow.definition.StateExecution).- Parameters:
execution- The workflow execution context.- Returns:
- Action to go to schedule or failed state.
-
handleFailureImpl
Logs an error and continues. Override for custom error handling.- Parameters:
execution- The workflow execution context.- Returns:
- True if workflow should be rescheduled. False to go to failed state and wait for manual actions.
-
waitForWorkToFinish
CallswaitForWorkToFinishImpl(io.nflow.engine.workflow.definition.StateExecution)to check if this instance should wait for work to finish or move to schedule state.- Parameters:
execution- The workflow execution context.- Returns:
- Action to retry later or move to schedule state.
-
waitForWorkToFinishImpl
Returns null to move to schedule state immediately if there are no incomplete child workflows, or current time plus 1 hour to check again later. Override for custom logic.- Parameters:
execution- The workflow execution context.- Returns:
- Time when check should be retried. Null to go to schedule state immediately.
-