explaingit

javan/whenever

8,871RubyAudience · developerComplexity · 2/5Setup · easy

TLDR

Whenever is a Ruby gem that lets you write recurring server tasks in plain readable Ruby syntax instead of cryptic cron expressions, then converts them into standard crontab entries automatically.

Mindmap

mindmap
  root((whenever))
    What it does
      Readable cron syntax
      Generates crontab
      Rails scheduling
    Schedule Styles
      every 3.hours
      every :sunday
      every 1.day at time
    Job Types
      Shell command
      Rake task
      Rails runner
    Integrations
      Capistrano deploy
      Multi-environment
      Email output config
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Schedule a nightly database cleanup task in a Rails app using readable Ruby syntax like 'every 1.day, at: 4am'.

USE CASE 2

Set up a recurring Rake task to send a digest email every Sunday at noon.

USE CASE 3

Automatically update the server's crontab whenever you deploy a Rails app using Capistrano.

USE CASE 4

Run a shell command every 3 hours using a clean schedule.rb file instead of editing crontab manually.

Tech stack

RubyRuby on RailsCapistrano

Getting it running

Difficulty · easy Time to first run · 30min

Requires Ruby and Bundler, Capistrano integration needs additional configuration in your deploy.rb file.

License information is not described in the explanation.

In plain English

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.

Copy-paste prompts

Prompt 1
Write a schedule.rb file using Whenever to run a Rails rake task every day at 6am and a cleanup task every Sunday.
Prompt 2
Show me how to integrate Whenever with Capistrano so cron jobs update automatically on every deploy.
Prompt 3
Convert this cron expression '0 */3 * * * /usr/bin/ruby /app/script/run.rb' into Whenever syntax.
Prompt 4
How do I define a custom job type in Whenever for a background task that is not a Rake task or shell command?
Prompt 5
Set up Whenever to send a digest email every Sunday at noon using a Rails mailer method call.
Open on GitHub → Explain another repo

← javan on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.