forked from sidekiq/sidekiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clockwork.rb
44 lines (35 loc) · 878 Bytes
/
clockwork.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Sidekiq defers scheduling to other, better suited gems.
# If you want to run a job regularly, here's an example
# of using the 'clockwork' gem to push jobs to Sidekiq
# regularly.
# require boot & environment for a Rails app
# require_relative "../config/boot"
# require_relative "../config/environment"
require "clockwork"
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
class HourlyWorker
include Sidekiq::Worker
def perform
cleanup_database
format_hard_drive
end
end
module Clockwork
# Kick off a bunch of jobs early in the morning
every 1.day, 'my_worker.late_night_work', :at => '4:30 am' do
MyWorker.late_night_work
end
every 1.hour do
HourlyWorker.perform_async
end
end