Resque Scheduler Example Save

This is an example rails app that uses resque scheduler to manage delayed, recurring and scheduled jobs.

Project README

Rails Resque Scheduler Example

This is an example rails app that shows how to use resque + resque scheduler to run delayed jobs and scheduled jobs.

Getting Started

Dependencies: Resque requires redis to run. Our initializer assumes redis is running locally. If you have another redis server running elsewhere, change it in /config/initializers/resque.rb.

Start the rails server and resque admin: $ rails s

Start the scheduler: $ rake resque:scheduler

  • Every 30 seconds you should see a new job get added to the queue
    • 2012-02-17 16:19:59 queueing MyJob (do_my_job)

Start the worker: $ rake resque:work

  • Every 30 seconds you should see the output of the perform method in the MyJob class
    • Doing my job

What's Inside?

Required Gems

gem 'resque' # background jobs
gem 'resque-scheduler' # job scheduling

Home for your job classes: /app/jobs/

# Example: /app/jobs/myjob.rb

module MyJob
  @queue = :my_job_queue
  def self.perform()
    # Do anything here, like access models, etc
    puts "Doing my job"

Job Schedule

Define job schedules in /config/resque_schedule.yml:

  every: 30s
  class: MyJob
  description: Runs the perform method in MyJob

For ways to define delayed jobs and different schedules, check here.


/config/initializers/resque.rb: configures redis, link jobs folder and reads the schedule at /config/resque_schedule.yml.

Rake tasks

Make the resque tasks available to rake and set default environment variables.

Rakefile: require 'resque/tasks'

Set the default queue environment variable: /lib/tasks/resque.rake:

require 'resque/tasks'
require 'resque_scheduler/tasks'

task "resque:setup" => :environment do
  ENV['QUEUE'] = '*'

Resque admin

This code in / will run the resque admin site when you start the normal rails server:

run \
  "/"       => ResqueScheduler::Application,
  "/resque" =>
Open Source Agenda is not affiliated with "Resque Scheduler Example" Project. README Source: jherrm/Resque-Scheduler-Example
Open Issues
Last Commit
11 years ago

Open Source Agenda Badge

Open Source Agenda Rating