From ef352f6b641341dd935a516315c93df05725bcab Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Fri, 2 Mar 2012 17:01:13 -0800 Subject: [PATCH] Create example of whenever integration, GH-66 --- examples/scheduling.rb | 37 +++++++++++++++++++++++++++++++++++++ lib/sidekiq/version.rb | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 examples/scheduling.rb diff --git a/examples/scheduling.rb b/examples/scheduling.rb new file mode 100644 index 00000000..e7d4ff90 --- /dev/null +++ b/examples/scheduling.rb @@ -0,0 +1,37 @@ +# Sidekiq defers scheduling to other, better suited gems. +# If you want to run a job regularly, here's an example +# of using the 'whenever' gem to push jobs to Sidekiq +# regularly. + +class MyWorker + include Sidekiq::Worker + + def perform(count) + puts "Job ##{count}: Late night, so tired..." + end + + def self.late_night_work + 10.times do |x| + perform_async(x) + end + end +end + +# Kick off a bunch of jobs early in the morning +every 1.day, :at => '4:30 am' do + runner "MyWorker.late_night_work" +end + + +class HourlyWorker + include Sidekiq::Worker + + def perform + cleanup_database + format_hard_drive + end +end + +every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot + runner "HourlyWorker.perform_async" +end diff --git a/lib/sidekiq/version.rb b/lib/sidekiq/version.rb index b3044e13..72c72b5b 100644 --- a/lib/sidekiq/version.rb +++ b/lib/sidekiq/version.rb @@ -1,3 +1,3 @@ module Sidekiq - VERSION = "0.8.0" + VERSION = "0.9.0" end