Class CronWorkflow

Direct Known Subclasses:
MaintenanceWorkflow

public abstract class CronWorkflow extends WorkflowDefinition
Workflow that wakes up periodically to execute a task.
  • Field Details

    • VAR_SCHEDULE

      public static final String VAR_SCHEDULE
      Name of the state variable that stores schedule in cron syntax.
      See Also:
    • 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 Details

    • 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 Details

    • schedule

      public NextAction schedule(StateExecution execution, String cron)
      Determines the next execution time for the doWork state by calling getNextActivationTime(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)
      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)
      Calls waitForWorkToFinishImpl(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.