Skip to content
Advertisement

Is it possible to check if cronjob is running in Symfony application?

I am currently working on the project that has over 20 crons. Some of them are pretty long processes. It was built on Symfony 2.8, so we decided to upgrade it to 3.4 LTS.

After the upgrade we noticed that, if there is ongoing cron job (long process) and we push some changes to Prod environment we get this error:

Fatal Compile Error: require(): Failed opening required '/.../cache/prod/

Turns out, that when we deploy the changes, cached container (in var/cache/prod/ContainerXXXXXX) changed the XXXXXX value. Or in other words, we clear the cache (during deploy) and then it generates new Container in cache directory. More about this problem: https://github.com/symfony/symfony/issues/25654 .

So, I came up with the idea, add a script with a while loop (?) which checks if there is any running crons, if not run the deploy.

But the question is, is there a way to check this in current situation?

Advertisement

Answer

There are many ways to achieve this. Just any kind of semaphore (a file, a database record) to store the “running” status and have the same process clear it when it’s done.

Any deployment job should check the value of this semaphore before continuing. A simple flat file would be easiest, since you may not have access to more sophisticated features during deployment, but reading a text file should be easy no matter what kind of of deployment process you are using.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement