Arun
Arun

Reputation: 2572

Multiple cron jobs running for a same tasks

I have a cron job which runs every minute. Sometimes, if the cron is running more than a minute then another cron job is instantiated to do the same task. Hence duplicate cron jobs are created which is NOT I want. I want to make a conditional check that if a cron for a specific task is running, wait till the cron job completes or skip creating new cron job till the existing cron completes.

Upvotes: 0

Views: 985

Answers (1)

pieterlouw
pieterlouw

Reputation: 81

Create a text file somewhere which will store a value. (for example 0 or 1) When the task execute, change the value to 1. In the cron job, add a check that if the value in the file is 1 then don't execute the job. When your task is complete, remember to switch the value back to the default (for example 0).

You can even create a file when the task starts, and delete the file when task end, and only execute the cron job if file doesn't exist.

You can even put the check in the task itself instead of cluttering your cron table

Upvotes: 1

Related Questions