Parallel cron - PostponedTaskCron

PostponedTaskCron can run scheduled tasks since version 5.7.40. It is a so-called "Parallel cron" — a cron that can be cloned and run multiple times simultaneously, allowing a larger number of long-running tasks to be processed.

Before starting PostponedTaskCron, you must deactivate the Cron! cron. Do not re-enable it afterwards — PostponedTaskCron replaces the original Cron!

Parallel deployment setup

To use PostponedTaskCron for parallel processing of scheduled tasks, follow these steps:

  1. Disable the Cron cron
  2. Create as many PostponedTaskCron instances as you need and your server performance allows. It is recommended to start with 2 and increase gradually.
  3. Set each instance to run every 5 minutes (for example), offset by 1 minute from the previous one — so that instances do not trigger at the same time.
  4. Alternate the startFromNewest parameter — set even instances to true, odd instances to false (crons working against each other)
  5. Set a low value for the limit parameter on all instances (e.g. 10)
Example configuration with 4 instances:
PostponedTaskCron 1 – 10:01, every 5 min, limit: 10, startFromNewest: false
PostponedTaskCron 2 – 10:02, every 5 min, limit: 10, startFromNewest: true
PostponedTaskCron 3 – 10:03, every 5 min, limit: 10, startFromNewest: false
PostponedTaskCron 4 – 10:04, every 5 min, limit: 10, startFromNewest: true
Key recommendations: set a low limit, run crons frequently, alternate the sort direction (startFromNewest), and ensure individual instances do not trigger at the same time.

Configuration

The following parameters can be configured within the cron:

fromTime

Defines from what point in time the cron will pick up scheduled tasks. Accepts a string or a timestamp. Default is null (which means 1970). This setting is useful if, for some reason, an additional cron needs to start processing tasks only from a specific date. It acts as a safeguard for situations where one cron becomes overloaded and cannot start another.

lockTtl

The duration for which a task is locked — during this period, the task cannot be activated. For the cron to process and activate a scheduled task, it must successfully write a unique record to Redis. If it fails to acquire the lock, the task is skipped. This ensures that two or more crons do not attempt to activate the same task simultaneously. Locks are not explicitly released — they are left to expire naturally. The default value is 30 minutes (1800000 ms). A locked task can therefore only be activated again after this period has elapsed.

limit

Available since 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: 1000.

startFromNewest

Available since version 5.7.71. Determines the sort order of tasks being processed. A value of true sorts from newest to oldest, false from oldest to newest. Type: boolean. Default: false.

Frantisek Brych Updated by Frantisek Brych

Crons

Contact

Syca (opens in a new tab)

Powered by HelpDocs (opens in a new tab)