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
public abstract class CronWorkflow extends WorkflowDefinition
Workflow that wakes up periodically to execute a task.
-
-
Field Summary
Fields Modifier and Type Field Description static WorkflowStateDISABLEDstatic WorkflowStateDO_WORKstatic WorkflowStateFAILEDstatic WorkflowStateHANDLE_FAILUREstatic WorkflowStateSCHEDULEStates of cron workflow.static StringVAR_SCHEDULEName of the state variable that stores schedule in cron syntax.static WorkflowStateWAIT_FOR_WORK_TO_FINISH-
Fields inherited from class io.nflow.engine.workflow.definition.WorkflowDefinition
allowedTransitions, failureTransitions
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCronWorkflow(String type)Extend cron workflow definition.protectedCronWorkflow(String type, WorkflowSettings settings)Extend cron workflow definition with customized workflow settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.joda.time.DateTimegetNextActivationTime(StateExecution execution, String cron)Calculates next activation time based on cron state variable.NextActionhandleFailure(StateExecution execution)Tries to handle failures by callinghandleFailureImpl(io.nflow.engine.workflow.definition.StateExecution).protected booleanhandleFailureImpl(StateExecution execution)Logs an error and continues.NextActionschedule(StateExecution execution, String cron)Determines the next execution time for the doWork state by callinggetNextActivationTime(io.nflow.engine.workflow.definition.StateExecution, java.lang.String).NextActionwaitForWorkToFinish(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, setName
-
Methods inherited from class io.nflow.engine.model.ModelObject
equals, hashCode, toString
-
-
-
-
Field Detail
-
VAR_SCHEDULE
public static final String VAR_SCHEDULE
Name of the state variable that stores schedule in cron syntax.- See Also:
- Constant Field Values
-
SCHEDULE
public static final WorkflowState SCHEDULE
States of cron workflow.
-
DO_WORK
public static final WorkflowState DO_WORK
-
WAIT_FOR_WORK_TO_FINISH
public static final WorkflowState WAIT_FOR_WORK_TO_FINISH
-
HANDLE_FAILURE
public static final WorkflowState HANDLE_FAILURE
-
DISABLED
public static final WorkflowState DISABLED
-
FAILED
public static final WorkflowState FAILED
-
-
Constructor Detail
-
CronWorkflow
protected CronWorkflow(String type, WorkflowSettings settings)
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
protected CronWorkflow(String type)
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 Detail
-
schedule
public NextAction 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).- Parameters:
execution- The workflow execution context.cron- The cron state variable.- Returns:
- Action to go to doWork state at scheduled time.
-
getNextActivationTime
protected org.joda.time.DateTime getNextActivationTime(StateExecution execution, String cron)
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
public NextAction handleFailure(StateExecution execution)
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
protected boolean handleFailureImpl(StateExecution execution)
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
public NextAction 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.- Parameters:
execution- The workflow execution context.- Returns:
- Action to retry later or move to schedule state.
-
waitForWorkToFinishImpl
protected org.joda.time.DateTime waitForWorkToFinishImpl(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. Override for custom logic.- Parameters:
execution- The workflow execution context.- Returns:
- Time when check should be retried. Null to go to schedule state immediately.
-
-