You are reading the documentation for an outdated Corteza release. 2023.9 is the latest stable Corteza release.

Delay and Schedule Workflows

Corteza workflow allows you to schedule or delay its execution. This can be a powerful tool when working with external services that throttle their API usage or when a task should be performed in an interval, for example monthly subscription renewal.

To achieve this, you are provided with a delay step delay and a deferred trigger trigger.

When you use a delay or a prompt step, the workflow becomes asynchronous and can no longer invalidate actions like create, update, or delete a record.

Operations such as "confirm record creation" are currently not possible with workflows. If you need to perform value validation or sanitization, use field expressions instead.

The delay of execution

The delay step delay allows you to explicitly pause the workflow’s execution for a set period of time.

This type of delaying is common when working with APIs that throttle their access. To exemplify; let’s say that the API allows 10 calls per minute and we wish to fetch 100 items. A possible execution is as it follows:

delay example

In case you wish to wait for an action performed by a user (such as a confirmation), use a prompt step instead.

Execution scheduling

Execution scheduling is performed by configuring the trigger trigger to run in an interval or at a specific timestamp.

Interval

An interval trigger allows you to run the workflow in a specified interval. This can be used to perform routine daily tasks or process larger data in batches.

A good example is a subscription service where it is necessary to renew the subscriptions of the clients on a monthly basis. We define an interval that executes the workflow each day, determine what clients need to be renewed that day and renew them.

interval example

The form of the above example should not be used in production. The actual workflow should implement error handling, transaction logging, and email notifications.

To define an interval trigger, click on the click on the configuration icon cog and specify the system as the resource resource with the on interval event.

The interval is defined as a chron expression and can be extremely flexible. You can also use this amazing tool to verify that your expressions are valid.

Common cron examples:
  • every hour at minute 0: 0 * * * *

  • every 30 minutes (0 and 30): 0/30 * * * *

  • every day at the start of the day: 0 0 * * *

  • every month at the start of month: 0 0 1 * *

You can define multiple intervals under the same trigger.

Timestamp

A timestamped trigger allows you to run the workflow at a specified time.

To illustrate; you have just received a new client that requested a series of deadlines where they would like to see the current progress. We could define a scheduled workflow that is executed at each one of the timestamps. The workflow would aggregate all of the completed tickets into an email and send it off to the client.

schedule example

Timestamps are defined in the ISO 8601, YYYY-MM-DDThh:mm:ssZ format.

You can define multiple timestamps under the same trigger.

Execution timeout

Corteza workflows' execution does not timeout by default (the workflow can run indefinitely).

If your use-case requires you to define a timeout, you can implement this manually.

The below example does two things:
  • Schedule a timeout after 10sec of execution,

  • repeat the iterator indefinitely.

manual timeout
Workflow step details:
  1. (1) Test trigger:

    • resource: System

    • event: onManual

    • enabled: checked

  2. (2) Fork:

    • gateway: Inclusive

    • conditions:

      • true

      • true

  3. (3) Wait 10sec:

    • offset: 10

  4. (4) Log context timeout:

    • type: Log debug message

    • arguments:

      • message:

        • value type: constant

        • value: Context timeout

  5. (5) Context timeout: /

  6. (6) Repeat indefinitely:

    • type: Condition

    • arguments:

      • while:

        • value type: expression

        • value: true

  7. (7) Log iteration:

    • type: Log debug message

    • arguments:

      • message:

        • value type: constant

        • value: Iterator loop

  8. (8) Done: /

  9. (9) Completed: /