pg_cron
pg_cron copied to clipboard
Run multiple instances of a job
I have a task that is scheduled to run every minute. Sometimes, this task can take longer than 1 minute to run, and in that event I'd like to start a second instance of the same task running in parallel (for computational efficiency reasons). Unfortunately, this doesn't seem to be supported. From the docs:
pg_cron can run multiple jobs in parallel, but it runs at most one instance of a job at a time. If a second run is supposed to start before the first one finishes, then the second run is queued and started as soon as the first run completes.
I can think of several ways to simulate this behavior (e.g. by adding a second "dummy" instance that has internal logic to only do the task if the other instance isn't running), but this would be very cumbersome. What I'd ideally like is to be able to specify a maximum number of parallel instances that can run per task. By setting this to 1, you'd get the current behavior, be we could set this to a higher number to enable more parallelism for certain tasks. The purpose for having the user controlled limit, is to prevent the cron tasks from accidentally consuming all the resources on the server.
our fork is plan to schedule the feature(fixed rate, on fixed delay, and next interval) at end of this month. https://github.com/hslightdb/pg_cron.