Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I use for simple cron jobs management in PHP project?

I want a simple cron-like management in PHP project there are some things I would like to have:

  1. php job worker is just plain script that is placed in some subdir inside project directory
  2. there is subtree like /cron/daily, /cron/monthly ... etc in the project root that contains all that workers
  3. there is no need to mess with crontab with every worker added.
  4. all scripts are run by something like run-parts with the corresponding frequency, and their respective output is logged into separate files like /var/log/projectname/cron/daily/somescript.log
  5. would be great to have /cron/daemon dir containing scripts that should be run forever (minutely) but no more than 1 instance

I've had experience with that kind of scheduling system in one project and loved it. It provides a number of neat things:

  • jobs are project scripts and reside in project dir, tracked by git.
  • no need for crontab messing.
  • logs are sorted out.
  • daemons are easy to build.

I would just use /bin/run-parts on project /cron subdirs, but didn't manage to split logs as I wanted. And splitted logging is very nice feature to have.

So, I just thought this kind of systems were created many times before, is there any ready to use solution for PHP project? Basically it's just some more smart run-parts equivalent. Should just write it once again?

P.S. There are many more job-queue specific solutions like Gearman. They are great, but this quesion is about project cron jobs lightweight solution.

like image 368
evgenyq Avatar asked Nov 15 '22 03:11

evgenyq


1 Answers

We've taken a slightly different approach at my current job. We use Jenkins (formerly Hudson) for our PHP related scheduling needs. It's nice because you can leverage the existing infrastructure for notifications (jabber, email, etc), and it sits along side our other build jobs for code releases. There's also the ability to watch console output in real time, get transcripts of every run, etc.

I documented the way we organize our PHP jobs recently so that we can easily leverage our application framework from CLI, which is how Jenkins interfaces with the jobs.

Here's the post about organizing PHP batch jobs for use with Jenkins or Hudson:

http://blog.shupp.org/2011/03/15/organizing-php-batch-jobs/

like image 122
Bill Shupp Avatar answered Dec 11 '22 15:12

Bill Shupp