Schedule a nightly database cleanup task in a Rails app using readable Ruby syntax like 'every 1.day, at: 4am'.
Set up a recurring Rake task to send a digest email every Sunday at noon.
Automatically update the server's crontab whenever you deploy a Rails app using Capistrano.
Run a shell command every 3 hours using a clean schedule.rb file instead of editing crontab manually.
Requires Ruby and Bundler, Capistrano integration needs additional configuration in your deploy.rb file.
Whenever is a Ruby gem that makes it easier to write and manage scheduled tasks on a server. Scheduled tasks are jobs you want the server to run automatically on a recurring basis, like generating a nightly report, clearing old records from a database, or sending a digest email every morning. On Unix and Linux servers, this scheduling is traditionally handled by a system called cron, which runs commands at specified intervals. The problem with cron is that its native syntax is terse and hard to read. Whenever lets you define those same schedules in plain Ruby code using a more readable style. Instead of cryptic cron expressions, you write things like every 3.hours, every :sunday, at: '12pm', or every 1.day, at: '4:30 am'. You put these definitions in a file called schedule.rb, then run the whenever command to convert them into standard cron syntax and write that into the server's crontab file. The gem ships with three built-in job types: running a shell command directly, running a Rake task (a common way Ruby apps define utility scripts), and running code inside a Rails application. You can also define custom job types if your project has a different kind of recurring task. Whenever also integrates with Capistrano, a deployment tool popular with Ruby on Rails projects, so that the crontab file on the server can be automatically updated whenever you deploy new code. This avoids the common problem of deployment and scheduled tasks falling out of sync. The README is thorough and covers time parsing options, email configuration for job output, comment annotations, and multi-environment setups. The full README is longer than what was shown.
← javan on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.