Note that there are some explanatory texts on larger screens.

plurals
  1. POHandle "race-condition" between 2 cron tasks. What is the best approach?
    primarykey
    data
    text
    <p>I have a cron task that runs periodically. This task depends on a condition to be valid in order to complete its processing. In case it matters this condition is just a SELECT for specific records in the database. If the condition is not satisfied (i.e the SELECT does not return the result set expected) then the script exits immediately.<br> This is bad as the condition would be valid soon enough (don't know how soon but it will be valid due to the run of another script).<br> So I would like somehow to make the script more robust. I thought of 2 solutions: </p> <ol> <li>Put a <code>while</code> loop and <code>sleep</code> constantly until the condition is valid. This should work but it has the downside that once the script is in the loop, it is out of control. So I though to additionally after waking up to check is a specific file exists. If it does it "understands" that the user wants to "force" stop it. </li> <li>Once the script figures out that the condition is not valid <em>yet</em> it appends a script in crontab and stops. That seconds script continually polls for the condition and if the condition is valid then restart the first script to restart its processing. This solution to me it seems to work but I am not sure if it is a good solution. E.g. perhaps programatically modifying the crontab is a bad idea? </li> </ol> <p>Anyway, I thought that perhaps this problem is common and could have a standard solution, much better than the 2 I came up with. Does anyone have a better proposal? Which from my ideas would be best? I am not very experienced with cron tasks so there could be things/problems I could be overseeing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. COIf one job depends on the other, can you run them in sequence? http://stackoverflow.com/questions/9639434/running-two-commands-sequentially-in-a-cron-job
      singulars
    2. CO@rutter:No because the other job is designed to run in small intervals constantly and do its processing of really big data in small "batches" (runs in days) and so the second cron task is scheduled approximately when the task ends but sometimes the task has not finished completely at that point. Additionally it does not make sense to schedule the second the task e.g. 10 hours later since 1)the synchronization issue is in a small interval 2)the processing of the second script also takes a while so just rescheduling it hours later destroys the process outcome we expect completely off
      singulars
    3. COSo most often, you run `ScriptA`, but sometimes you want to run `ScriptA && ScriptB`? You can use conditional logic in cron entries (perhaps by time of day or number of runs), or the ScriptA could contain some logic to launch ScriptB when appropriate, or your cron entry could invoke ScriptC which runs either/both commands as needed. I favor those sorts of solutions. If you're set on the sleep-until-ready mechanic (which should work!), the only suggestion I'd make is to limit the number of sleep cycles ScriptB will wait for.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload