pg_cron
pg_cron copied to clipboard
Crons not running in parallel
When cron.use_background_workers is on, all cron jobs wait for the longest running job then kick off again.
Setup: create a procedure that only sleeps:
create or replace procedure test_cron(sleep_time integer)
language plpgsql
as $$
begin
perform pg_sleep(sleep_time);
end;
$$;
Schedule several crons that sleep different times:
select schedule('test_a', '* * * * *', 'call cron.test_cron(25);');
select schedule('test_b', '* * * * *', 'call cron.test_cron(55);');
select schedule('test_c', '* * * * *', 'call cron.test_cron(85);');
select schedule('test_d', '* * * * *', 'call cron.test_cron(300);');
When cron.use_background_workers is off, test_a runs every minute as expected. test_d runs every 5 minutes as expected.
When cron.use_background_workers is on, all 4 run every 5 minutes.
Looks like that https://github.com/citusdata/pg_cron/pull/152 introduced the issue. Did a few tests and the issue was not there on v1.3.1.
@marcocitus what do you think about making the QUEUE_SIZE configurable and revert the fix in https://github.com/citusdata/pg_cron/pull/152?
This place is very strange, something doesn't feel right
@marcocitus I think the completion of the task has no necessary relationship with the state of GetBackgroundWorkerPid, right?
Definitely hope to see this bug fixed as I just discovered it in the worst way possible today. Will use connections rather than background workers for now.