Skip to content

chrisjpowers/multiserver_whenever

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multiserver Whenever

Created by Chris Powers 12/7/2010

Provides the multiserver_whenever command for generating host-specific crontabs with role-based whenever files. This is very handy for when you need to deploy different crontabs to different staging/production servers, but still want to leverage the whenever gem’s DSL and build tools.

Learn all about the original whenever gem at github.com/javan/whenever.

Installation

Just install the multiserver_whenever gem per usual:

gem install multiserver_whenever

Generating Document Structure with MultiserverWheneverize

Taking off of the whenever gem’s wheneverize, this gem provides the multiserver_wheneverize command to generate the initial file structure:

cd /path/to/your_app
multiserver_wheneverize

The generated file structure looks like:

- your_app/
  - config/
    - whenever.yml
    - whenever/
      - do_not_remove.rb
      - example.rb

Configuration

The config/whenever.yml file is a hash where the keys are server hostnames and the values are arrays of “roles”.

Let’s say that I have two servers with hostnames app_server and db_server. I need to set app-related crontabs on app_server, db-related crontabs on db_server and some shared crontabs on both. To do this, I will first create three whenever files in config/whenever:

- your_app/
  - config/
    - whenever.yml
    - whenever/
      - app.rb
      - db.rb
      - do_not_remove.rb
      - shared.rb

The contents of each of these files is regular whenever code (see github.com/javan/whenever).

Then in our config/whenever.yml file we map our hostnames to the cron roles:

---
app_server:
  - app
  - shared
db_server:
  - db
  - shared

Now when you run the multiserver_whenever command on one of your servers, it will only apply the whenever files that are specified in your config/whenever.yml file.

Running multiserver_whenever

If you are using the whenever rake and runner commands, you may need to specify a Rails environment. It defaults to using production, but you can simply pass a different environment to the multiserver_whenever command instead:

multiserver_whenever staging

Deployment with Capistrano

In your Capistrano deployment code, you should be able to add something like this to run multiserver_whenever on deployment:

namespace :whenever do
  desc "Update your whenever-generated crontabs"
  task :update do
    run "cd #{release_path}; multiserver_whenever #{rails_env}"
  end
  after "deploy:update", "whenever:update"
end

About

Provides the multiserver_whenever command for generating host-specific crontabs with role-based whenever files.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages