Skip to content

WorkflowOptions

Quanzheng Long edited this page Apr 3, 2024 · 2 revisions

iWF let you deeply customize the workflow behaviors with the below options.

IdReusePolicy for WorkflowId

At any given time, there can be only one WorkflowExecution running for a specific workflowId. A new WorkflowExecution can be initiated using the same workflowId by setting the appropriate IdReusePolicy in WorkflowOptions.

  • ALLOW_IF_NO_RUNNING
    • Allow starting workflow if there is no execution running with the workflowId
    • This is the default policy if not specified in WorkflowOptions
  • ALLOW_IF_PREVIOUS_EXITS_ABNORMALLY
    • Allow starting workflow if a previous Workflow Execution with the same Workflow Id does not have a Completed status. Use this policy when there is a need to re-execute a Failed, Timed Out, Terminated or Cancelled workflow execution.
  • DISALLOW_REUSE
    • Not allow to start a new workflow execution with the same workflowId.
  • ALLOW_TERMINATE_IF_RUNNING
    • Always allow starting workflow no matter what -- iWF server will terminate the current running one if it exists.

Note that the behavior is limited by Cadence/Temporal workflow retention, which is configured at domain/namespace level. If a workflow is deleted after retention expired, the workflowId can be started regardless of any Policy

CRON Schedule

iWF allows you to start a workflow with a fixed cron schedule like below

// CronSchedule - Optional cron schedule for workflow. If a cron schedule is specified, the workflow will run
// as a cron based on the schedule. The scheduling will be based on UTC time. The schedule for the next run only happens
// after the current run is completed/failed/timeout. If a RetryPolicy is also supplied, and the workflow failed
// or timed out, the workflow will be retried based on the retry policy. While the workflow is retrying, it won't
// schedule its next run. If the next schedule is due while the workflow is running (or retrying), then it will skip
that
// schedule. Cron workflow will not stop until it is terminated or cancelled (by returning cadence.CanceledError).
// The cron spec is as follows:
// ┌───────────── minute (0 - 59)
// │ ┌───────────── hour (0 - 23)
// │ │ ┌───────────── day of the month (1 - 31)
// │ │ │ ┌───────────── month (1 - 12)
// │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)
// │ │ │ │ │
// │ │ │ │ │
// * * * * *

NOTE:

  • iWF also supports more advanced cron expressions
  • The crontab guru site is useful for testing your cron expressions.
  • To cancel a cron schedule, use terminate of cancel type to stop the workflow execution.
  • By default, there is no cron schedule.

RetryPolicy for workflow

Workflow execution can have a backoff retry policy which will retry on failed or timeout.

By default, there is no retry policy.

Initial Search Attributes

Client can specify some initial search attributes when starting the workflow.

By default, there is no initial search attributes.