crondonkulous
DESCRIPTION:
Ever need to have process run regularly for your rails app? Ever want to use cron as the answer? Sure you have! So lets get it done.
It sounds pretty easy… use cron to automate the periodic execution of some rake tasks… but in practice we run into a couple of problems:
-
Keeping the cron tasks in sync with your capistrano deploys
-
preventing the cron tasks from running while you are deploying/migrating
-
keeping the cron tasks from stepping on each other if they are taking longer than expected to run
-
having cron logging output intermingled with logging from your controllers
Ever have any of these problems? I know I have. So lets solve them once and for all, and bundle it into a gem with some reusable conventions. Enter Crondonkulous!
Here’s what you get:
-
a crontab file with all the silly little syntax you need to specify tasks for:
-
every minute
-
every 5 minutes
-
every 15 minutes
-
every hour
-
every day
-
every week
-
every month
-
-
a crondonkulous.rake template that separates logging out of your controller’s log file, with a sane naming convention for logs
-
a lockfile, so that rake tasks invoked with cron won’t start if there is another one running (and you specify the number of times to retry)
-
capistrano tasks that:
-
stop the cronned rake tasks while deploying
-
wait until any running ones are done before continuing the deploy
-
load in any new cron entries when the webapp restarts.
-
REQUIREMENTS:
-
Its a gem for rails, so.. uh, all of that stuff.
-
a capistrano deploy (will gladly accept patches for vlad)
-
a server running cron that allows crontab entries by user
-
also relies on the lockfile gem
INSTALL:
-
sudo gem install bokmann-crondonkulous
-
./script/generate crondonkulous
-
follow the instructions to modify the files it puts in your project
HISTORY:
A couple of years ago I wrote the ‘automate repeatable tasks’ recipe for the book Advanced Rails Recipes from Pragmatic Bookshelf. Some of these ideas are represented there, but they have evolved a lot as I have added better integration with capistrano, reliance on the lockfile gem, etc.
LICENSE:
(The MIT License)
Copyright © 2009 CodeSherpas Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.