Parallel cron - PostponedTaskCron

PostponedTaskCron can, from version 5.7.40, run scheduled tasks. It is a so-called "parallel cron" — a cron that can be cloned and run multiple times. This allows a larger number of long-running tasks to be processed.

Before starting PostponedTaskCron you must deactivate the Cron! cron. Do not turn it back on afterwards — PostponedTaskCron replaces the original Cron!

Parallel deployment procedure

To use PostponedTaskCron for parallel processing of scheduled tasks, follow this procedure:

  1. Turn off the Cron cron.
  2. Create as many PostponedTaskCron instances as you need. The current best practice is 4 instances — but the count can be scaled up freely depending on load and the environment's performance; 4 is by no means the ceiling.
  3. Set each instance to run every 5 minutes, offset against one another so that the crons don't run at the same moment. In the example below the offset is handled by combining seconds (01, 15, 30, 45) and the starting minute of the /5 interval (0, 1, 2, 3).
  4. Alternate the startFromNewest parameter — even instances true, odd instances false (the crons run toward each other).
  5. Set a low value of the limit parameter on all instances (25 in the example).
For even higher throughput it is possible to enable more cron backends on the environment. This must be configured by DevOps.
Concrete example configuration of 4 instances (best practice)

All instances run every 5 minutes throughout the day (hours expression *), share fromTime, lockTtl: 1800000 and limit: 25. They differ in the second, the starting minute of the /5 interval, and the startFromNewest parameter.

PostponedTaskCron (instance 1) — at second 01, every 5 minutes starting from minute 0
secondsminuteshoursdaysmonthsweekdays
010-59/5****
Parameters:
{
            "fromTime": "2025-09-25T06:00:00.000Z",
            "lockTtl": 1800000,
            "startFromNewest": false,
            "limit": 25
          }
PostponedTaskCron_2 — at second 15, every 5 minutes starting from minute 1
secondsminuteshoursdaysmonthsweekdays
151-59/5****
Parameters:
{
            "fromTime": "2025-09-25T06:00:00.000Z",
            "lockTtl": 1800000,
            "startFromNewest": true,
            "limit": 25
          }
PostponedTaskCron_3 — at second 30, every 5 minutes starting from minute 2
secondsminuteshoursdaysmonthsweekdays
302-59/5****
Parameters:
{
            "fromTime": "2025-09-25T06:00:00.000Z",
            "lockTtl": 1800000,
            "startFromNewest": false,
            "limit": 25
          }
PostponedTaskCron_4 — at second 45, every 5 minutes starting from minute 3
secondsminuteshoursdaysmonthsweekdays
453-59/5****
Parameters:
{
            "fromTime": "2025-09-25T06:00:00.000Z",
            "lockTtl": 1800000,
            "startFromNewest": true,
            "limit": 25
          }
Key recommendations: set a low limit, run the crons frequently, alternate the sort direction (startFromNewest — instances running toward each other) and ensure that individual instances do not run at the same moment. In the example this is ensured by combining different seconds (01/15/30/45) and different starting minutes of the /5 interval (0/1/2/3), so that the runs interleave.

Configuration

The following parameters can be set within the cron:

fromTime

Defines from when the cron will pick up scheduled tasks. A string or a timestamp can be provided. The default is null (which means 1970). This setting is useful when, for some reason, you need to configure an additional cron starting only from a specific date. It is essentially a safeguard for cases where one cron becomes overloaded and another cannot be started. In the example above it is set identically to "2025-09-25T06:00:00.000Z" on all instances.

lockTtl

The duration for which a task is locked; during this time the task cannot be activated. For the cron to process and activate a scheduled task, a unique record must be successfully written to Redis. If it does not obtain the lock, it skips the task. This ensures that two or more crons do not try to activate the same task at once. Locks are not explicitly released — they are left to expire. The default value is 30 minutes (1800000 ms). Such a task can therefore be activated only after that period.

limit

Available from version 5.7.71. The maximum number of items processed in a single run. The limit is applied separately for Events and InstanceTasks. Type: number. Default value: 1000. In the example above it is set to 25 on all instances.

startFromNewest

Available from version 5.7.71. Determines the sort order of the processed tasks. A value of true means sorting from newest to oldest, a value of false from oldest to newest. Type: boolean. Default value: false. In the example above the value alternates across the instances (false / true / false / true) so that the crons process the queue from both ends, toward each other.

Frantisek Brych Updated by Frantisek Brych

CleanupCron

Contact

Syca (opens in a new tab)

Powered by HelpDocs (opens in a new tab)