I have some pg_cron jobs that run at night time. They basically run some plpgsql Procedures and trigger based off CRON expressions.

The problem is that some of my JOBS are dependent on the jobs that run before them. I have been dealing with that by inserting a record into a utility table I have created, but it's annoying to me that even the 1st job runs and inserts this record, the other job is constantly re-triggering because of the CRON expression. I do indeed have a conditional statement in the 2nd and subsequent jobs so they don't run if the 1st job didn't insert its record into the utility table, but I don't see to find any way to completely outright prevent the other jobs from running.

Also, I don't know when the 1st job will end, so if I technically set a specific CRON time, the 1st job might not be done, and the 2nd will never run (which I don't want).

Ideally, there would be someway for me to link the jobs together (if 1st job runs and completes, run the 2nd) but I seem to only be able to set expressions like (* * * * *), where basically the job has to repeatedly check all day.

Is this the best approach? Is there an alternative to setting Cron expressions for the pg_cron jobs or a way to link jobs?

  • Why is this two jobs, if you don't want it to run as two jobs?
    – jjanes
    Oct 9, 2021 at 20:37
  • You could use pg_timetable, which supports chains of jobs. Oct 11, 2021 at 6:17
  • @jjanes because if its a SEPERATE job you can run it IN PARALLEL. I have 5 dependent jobs. If I call their Functions/Procedures in the first job, yes, it will run in sequence but I can't run them in parallel and I lose the speed . I can use the Background Workers on PG database
    – ennth
    Oct 20, 2021 at 23:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.