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

Delaying and scheduling 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 we want to perform some task in an interval, such as monthly subscription renewal.

To achieve this, we provide 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 record.

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

Delaying execution

The delay step delay allows you to explicitly pause the workflows' execution for a set period of time.

This type of delaying is common when working with APIs that throttle their access. To examplify; let’s say that the API allows 10 calls per minute and we wish to fetch 100 items. We could do something like the following:

delay example

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

Scheduling execution

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

Interval

Performing a task in an interval can be a powerful tool as it allows you to define an interval in which the workflow executes.

A good example is a subscription service where it is necessary to renew the subscriptions of the clients once a month. We define an interval that would execute 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.

An interval is defined by specifying the resource as a system, and the event as an interval in the trigger configuration (click on the configuration icon cog).

The interval is defined as a chron expression and can be as flexible as you could ever want it to be. 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

Performing a task at a specific date and time can be another powerful tool in your toolbox as it allows you to define exactly when an action should be performed.

To illustrate; we’ve 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: /