sidekiq-scheduler 0.4.1 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +23 -69
- data/bin/sidekiq-scheduler +4 -9
- data/lib/sidekiq-scheduler.rb +1 -3
- data/lib/sidekiq-scheduler/cli.rb +9 -5
- data/lib/sidekiq-scheduler/manager.rb +2 -57
- data/lib/sidekiq-scheduler/schedule.rb +6 -7
- data/lib/sidekiq-scheduler/version.rb +2 -2
- data/lib/sidekiq/scheduler.rb +11 -7
- data/lib/tasks/sidekiq-scheduler_tasks.rake +1 -1
- data/test/cli_test.rb +6 -1
- data/test/lib/sidekiq/scheduler_test.rb +97 -148
- data/test/schedule_test.rb +1 -5
- data/test/test_helper.rb +13 -9
- metadata +50 -54
- data/lib/sidekiq-scheduler/client.rb +0 -87
- data/lib/sidekiq-scheduler/worker.rb +0 -26
- data/test/client_test.rb +0 -136
- data/test/manager_test.rb +0 -65
- data/test/testing_test.rb +0 -38
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2Q1OGQ4ZGNkNzkwMWM2MWQ0MDI0MjY4MTAxMzZkZjAyZjNiMWU4Zg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Njk5ZjEzZmUwMGRmMDIyNmQzZDZkOTY4Njk0MmY4YzRjZmI5MTY2NA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzZhYzlhZDRkYWE3OWYwM2ZhOWY4ZjljYTBlMzE3ZDAyNTM2OGU5MDliNTNk
|
10
|
+
YjA3ODgxNDhkMzRiMmE1ZjMyYjUzMjljZDFiYWEwYzEwMGM3YWRkMzU5NTRl
|
11
|
+
YmRiZmI0ZTQ4ODEwMGQzMzcwNDVjMjE5ZTEyZWY1YjFlNmRmZDc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NTExMjEzMjA1M2FhNWYzMWY1Zjg1NzY5NTI3N2VhOTBhM2JkMTU0NjBkYzg3
|
14
|
+
ZmEyN2EyMTY1ZGVmNWZhOTQ4NDgzNzdiM2U4YzdiNmM4M2Y5ODE1ODIxZjNi
|
15
|
+
ZGE0ZWUzZjdhMDExYjQyNmEwZGZhMDNiNmI4Zjk3YTEyZWU0YTc=
|
data/README.md
CHANGED
@@ -1,35 +1,17 @@
|
|
1
1
|
# SidekiqScheduler
|
2
2
|
|
3
|
-
# Warning!
|
4
|
-
|
5
|
-
The original function of this gem was to add delayed jobs for a fixed amount of time.
|
6
|
-
This has been available directly within Sidekiq since Version 2.0. A lot of this code
|
7
|
-
should be considered redundant and might even conflict with the latest Sidekiq release.
|
8
|
-
|
9
|
-
Since I have upgraded my projects that made use of this gem to the core Sidekiq functions and
|
10
|
-
no longer make active use of this gem this project should be considered largely unmaintained.
|
11
|
-
|
12
3
|
## Description
|
13
4
|
|
14
5
|
sidekiq-scheduler is an extension to [Sidekiq](http://github.com/mperham/sidekiq)
|
15
|
-
that adds support for
|
6
|
+
that adds support for running scheduled.
|
16
7
|
|
17
8
|
This table explains the version requirements for redis
|
18
9
|
|
19
10
|
| sidekiq-scheduler version | required redis version|
|
20
11
|
|:--------------------------|----------------------:|
|
21
|
-
| >=
|
12
|
+
| >= 0.4.0 | >= 2.2.0 |
|
22
13
|
|
23
|
-
|
24
|
-
Delayed.
|
25
|
-
|
26
|
-
Scheduled jobs are like cron jobs, recurring on a regular basis. Delayed
|
27
|
-
jobs are resque jobs that you want to run at some point in the future.
|
28
|
-
The syntax is pretty explanatory:
|
29
|
-
|
30
|
-
MyWorker.perform_in(5.days, 'arg1', 'arg2') # run a job in 5 days
|
31
|
-
# or
|
32
|
-
MyWorker.perform_at(5.days.from_now, 'arg1', 'arg2') # run job at a specific time
|
14
|
+
Scheduled jobs are like cron jobs, recurring on a regular basis.
|
33
15
|
|
34
16
|
### Documentation
|
35
17
|
|
@@ -58,7 +40,6 @@ parsing provided by sidekiq you will need to use a configuration file to
|
|
58
40
|
override the scheduler options.
|
59
41
|
Available options are:
|
60
42
|
|
61
|
-
:resolution: <seconds between schedule runs>
|
62
43
|
:schedule: <the schedule to be run>
|
63
44
|
:dynamic: <if true the schedule can we modified in runtime>
|
64
45
|
|
@@ -74,55 +55,13 @@ NOTE: If the scheduler thread goes down for whatever reason, the delayed items
|
|
74
55
|
that should have fired during the outage will fire once the scheduler is
|
75
56
|
started back up again (even if it is on a new machine).
|
76
57
|
|
77
|
-
## Delayed jobs
|
78
|
-
|
79
|
-
Delayed jobs are one-off jobs that you want to be put into a queue at some point
|
80
|
-
in the future. The classic example is sending email:
|
81
|
-
|
82
|
-
MyWorker.perform_in(5.days, current_user.id)
|
83
|
-
|
84
|
-
This will store the job for 5 days in the Sidekiq delayed queue at which time
|
85
|
-
the scheduler will pull it from the delayed queue and put it in the appropriate
|
86
|
-
work queue for the given job. It will then be processed as soon as a worker is
|
87
|
-
available (just like any other Sidekiq job).
|
88
|
-
|
89
|
-
The `5.days` syntax will only work if you are using ActiveSupport (Rails). If you
|
90
|
-
are not using Rails, just provide `perform_in` with the number of seconds.
|
91
|
-
|
92
|
-
NOTE: The job does not fire **exactly** at the time supplied. Rather, once that
|
93
|
-
time is in the past, the job moves from the delayed queue to the actual work
|
94
|
-
queue and will be completed as workers are free to process it.
|
95
|
-
|
96
|
-
Also supported is `MyWork.perform_at` which takes a timestamp to queue the job.
|
97
|
-
|
98
|
-
The delayed queue is stored in redis and is persisted in the same way the
|
99
|
-
standard Sidekiq jobs are persisted (redis writing to disk). Delayed jobs differ
|
100
|
-
from scheduled jobs in that if your scheduler process is down or workers are
|
101
|
-
down when a particular job is supposed to be processed, they will simply "catch up"
|
102
|
-
once they are started again. Jobs are guaranteed to run (provided they make it
|
103
|
-
into the delayed queue) after their given queue_at time has passed.
|
104
|
-
|
105
|
-
One other thing to note is that insertion into the delayed queue is O(log(n))
|
106
|
-
since the jobs are stored in a redis sorted set (zset). I can't imagine this
|
107
|
-
being an issue for someone since redis is stupidly fast even at log(n), but full
|
108
|
-
disclosure is always best.
|
109
|
-
|
110
|
-
### Removing Delayed jobs
|
111
|
-
|
112
|
-
If you have the need to cancel a delayed job, you can do it like this:
|
113
|
-
|
114
|
-
# after you've enqueued a job like:
|
115
|
-
MyWorker.perform_at(5.days.from_now, 'arg1', 'arg2')
|
116
|
-
# remove the job with exactly the same parameters:
|
117
|
-
MyWorker.remove_delayed(<timestamp>, 'arg1', 'arg2')
|
118
|
-
|
119
58
|
## Scheduled Jobs (Recurring Jobs)
|
120
59
|
|
121
60
|
Scheduled (or recurring) jobs are logically no different than a standard cron
|
122
61
|
job. They are jobs that run based on a fixed schedule which is set at
|
123
62
|
startup.
|
124
63
|
|
125
|
-
The schedule is a list of
|
64
|
+
The schedule is a list of Sidekiq worker classes with arguments and a
|
126
65
|
schedule frequency (in crontab syntax). The schedule is just a hash, but
|
127
66
|
is most likely stored in a YAML like so:
|
128
67
|
|
@@ -164,6 +103,20 @@ seconds past the minute).
|
|
164
103
|
A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler)
|
165
104
|
for handling the heavy lifting of the actual scheduling engine.
|
166
105
|
|
106
|
+
### Loading the schedule
|
107
|
+
|
108
|
+
Let's assume your scheduled jobs are defined in a file called "config/scheduler.yml" under your Rails project,
|
109
|
+
you could create a Rails initializer called "config/initializer/scheduler.rb" which would load the job definitions:
|
110
|
+
|
111
|
+
require 'sidekiq/scheduler'
|
112
|
+
Sidekiq.schedule = YAML.load_file(File.expand_path("../../../config/scheduler.yml",__FILE__))
|
113
|
+
|
114
|
+
If you were running a non Rails project you should add code to load the workers classes before loading the schedule.
|
115
|
+
|
116
|
+
require 'sidekiq/scheduler'
|
117
|
+
Dir[File.expand_path('../lib/workers/*.rb',__FILE__)].each do |file| load file; end
|
118
|
+
Sidekiq.schedule = YAML.load_file(File.expand_path("../../../config/scheduler.yml",__FILE__))
|
119
|
+
|
167
120
|
### Time zones
|
168
121
|
|
169
122
|
Note that if you use the cron syntax, this will be interpreted as in the server time zone
|
@@ -204,12 +157,12 @@ Sidekiq uses a jobs array on workers for testing, which is supported by sidekiq-
|
|
204
157
|
|
205
158
|
This work is a partial port of [resque-scheduler](https://github.com/bvandenbos/resque-scheduler) by Ben VandenBos.
|
206
159
|
Modified to work with the Sidekiq queueing library by Morton Jonuschat.
|
207
|
-
|
208
|
-
Scheduling of recurring jobs has been addet to v0.4.0, thanks to [Adrian Gomez](https://github.com/adrian-gomez).
|
160
|
+
Scheduling of recurring jobs has been added to v0.4.0, thanks to [Adrian Gomez](https://github.com/adrian-gomez).
|
209
161
|
|
210
162
|
## Maintainers
|
211
163
|
|
212
164
|
* [Morton Jonuschat](https://github.com/yabawock)
|
165
|
+
* [Moove-IT](https://github.com/Moove-it)
|
213
166
|
|
214
167
|
## License
|
215
168
|
|
@@ -217,5 +170,6 @@ MIT License
|
|
217
170
|
|
218
171
|
## Copyright
|
219
172
|
|
220
|
-
Copyright
|
221
|
-
|
173
|
+
Copyright 2013 Moove-IT
|
174
|
+
Copyright 2012 Morton Jonuschat
|
175
|
+
Some parts copyright 2010 Ben VandenBos
|
data/bin/sidekiq-scheduler
CHANGED
@@ -1,21 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require 'sidekiq-scheduler/cli'
|
5
|
-
rescue LoadError
|
6
|
-
# Better way to do this in dev?
|
7
|
-
dir = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
8
|
-
$LOAD_PATH << dir if File.exist?("#{dir}/sidekiq-scheduler.rb")
|
9
|
-
require 'sidekiq-scheduler'
|
10
|
-
end
|
3
|
+
require 'sidekiq/cli'
|
11
4
|
|
12
5
|
begin
|
13
6
|
cli = Sidekiq::CLI.instance
|
14
7
|
cli.parse
|
8
|
+
|
9
|
+
require 'sidekiq-scheduler/cli'
|
15
10
|
cli.run
|
16
11
|
rescue => e
|
17
12
|
raise e if $DEBUG
|
18
13
|
STDERR.puts e.message
|
19
14
|
STDERR.puts e.backtrace.join("\n")
|
20
15
|
exit 1
|
21
|
-
end
|
16
|
+
end
|
data/lib/sidekiq-scheduler.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
require 'sidekiq-scheduler/manager'
|
2
1
|
require 'sidekiq/cli'
|
3
2
|
|
3
|
+
require 'sidekiq-scheduler/manager'
|
4
|
+
|
4
5
|
module SidekiqScheduler
|
5
6
|
module CLI
|
7
|
+
|
6
8
|
def self.included(base)
|
7
9
|
base.class_eval do
|
8
10
|
alias_method :run_manager, :run
|
@@ -11,21 +13,23 @@ module SidekiqScheduler
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def run_scheduler
|
14
|
-
scheduler_options = { :scheduler => true, :
|
16
|
+
scheduler_options = { :scheduler => true, :schedule => nil }
|
15
17
|
scheduler_options.merge!(options)
|
16
18
|
|
17
19
|
if options[:config_file]
|
18
20
|
file_options = YAML.load_file(options[:config_file])
|
19
21
|
options.merge!(file_options)
|
20
22
|
options.delete(:config_file)
|
23
|
+
parse_queues(options, options.delete(:queues) || [])
|
21
24
|
end
|
22
25
|
|
23
26
|
scheduler = SidekiqScheduler::Manager.new(scheduler_options)
|
24
|
-
scheduler.start
|
27
|
+
scheduler.start
|
25
28
|
run_manager
|
26
|
-
scheduler.stop
|
29
|
+
scheduler.stop
|
27
30
|
end
|
31
|
+
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
31
|
-
Sidekiq::CLI.send(:include, SidekiqScheduler::CLI)
|
35
|
+
Sidekiq::CLI.send(:include, SidekiqScheduler::CLI)
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'celluloid'
|
2
2
|
require 'redis'
|
3
|
-
require 'multi_json'
|
4
3
|
|
5
4
|
require 'sidekiq/util'
|
6
5
|
|
@@ -9,7 +8,6 @@ require 'sidekiq-scheduler/schedule'
|
|
9
8
|
|
10
9
|
module SidekiqScheduler
|
11
10
|
|
12
|
-
##
|
13
11
|
# The delayed job router in the system. This
|
14
12
|
# manages the scheduled jobs pushed messages
|
15
13
|
# from Redis onto the work queues
|
@@ -20,7 +18,6 @@ module SidekiqScheduler
|
|
20
18
|
|
21
19
|
def initialize(options={})
|
22
20
|
@enabled = options[:scheduler]
|
23
|
-
@resolution = options[:resolution] || 5
|
24
21
|
|
25
22
|
Sidekiq::Scheduler.dynamic = options[:dynamic] || false
|
26
23
|
Sidekiq.schedule = options[:schedule] if options[:schedule]
|
@@ -38,64 +35,12 @@ module SidekiqScheduler
|
|
38
35
|
elsif @enabled
|
39
36
|
Sidekiq::Scheduler.load_schedule!
|
40
37
|
end
|
41
|
-
|
42
|
-
schedule(true)
|
43
38
|
end
|
44
39
|
|
45
40
|
def reset
|
46
41
|
clear_scheduled_work
|
47
42
|
end
|
48
43
|
|
49
|
-
private
|
50
|
-
|
51
|
-
def clear_scheduled_work
|
52
|
-
redis do |conn|
|
53
|
-
queues = conn.zrange('delayed_queue_schedule', 0, -1).to_a
|
54
|
-
conn.del(*queues.map { |t| "delayed:#{t}" }) unless queues.empty?
|
55
|
-
conn.del('delayed_queue_schedule')
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def find_scheduled_work(timestamp)
|
60
|
-
loop do
|
61
|
-
break logger.debug("Finished processing queue for timestamp #{timestamp}") unless msg = redis { |r| r.lpop("delayed:#{timestamp}") }
|
62
|
-
item = MultiJson.decode(msg)
|
63
|
-
item['class'] = constantize(item['class']) # Sidekiq expects the class to be constantized.
|
64
|
-
Sidekiq::Client.push(item)
|
65
|
-
end
|
66
|
-
Sidekiq::Client.remove_scheduler_queue(timestamp)
|
67
|
-
end
|
68
|
-
|
69
|
-
def find_next_timestamp
|
70
|
-
timestamp = redis { |r| r.zrangebyscore('delayed_queue_schedule', '-inf', Time.now.to_i, :limit => [0, 1]) }
|
71
|
-
if timestamp.is_a?(Array)
|
72
|
-
timestamp = timestamp.first
|
73
|
-
end
|
74
|
-
timestamp.to_i unless timestamp.nil?
|
75
|
-
end
|
76
|
-
|
77
|
-
def schedule(run_loop = false)
|
78
|
-
watchdog("Fatal error in sidekiq, scheduler loop died") do
|
79
|
-
return if stopped?
|
80
|
-
|
81
|
-
# Dispatch loop
|
82
|
-
loop do
|
83
|
-
Sidekiq::Scheduler.update_schedule if Sidekiq::Scheduler.dynamic
|
84
|
-
break unless timestamp = find_next_timestamp
|
85
|
-
find_scheduled_work(timestamp)
|
86
|
-
end
|
87
|
-
|
88
|
-
# This is the polling loop that ensures we check Redis every
|
89
|
-
# second for work, even if there was nothing to do this time
|
90
|
-
# around.
|
91
|
-
after(@resolution) do
|
92
|
-
schedule(run_loop)
|
93
|
-
end if run_loop
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def stopped?
|
98
|
-
!@enabled
|
99
|
-
end
|
100
44
|
end
|
101
|
-
|
45
|
+
|
46
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
1
3
|
module SidekiqScheduler
|
2
4
|
module Schedule
|
3
5
|
|
@@ -30,9 +32,6 @@ module SidekiqScheduler
|
|
30
32
|
# :args can be any yaml which will be converted to a ruby literal and
|
31
33
|
# passed in a params. (optional)
|
32
34
|
#
|
33
|
-
# :rails_envs is the list of envs where the job gets loaded. Envs are
|
34
|
-
# comma separated (optional)
|
35
|
-
#
|
36
35
|
# :description is just that, a description of the job (optional). If
|
37
36
|
# params is an array, each element in the array is passed as a separate
|
38
37
|
# param, otherwise params is passed in as the only parameter to perform.
|
@@ -89,10 +88,10 @@ module SidekiqScheduler
|
|
89
88
|
# Note: values for class and custom_job_class need to be strings,
|
90
89
|
# not constants.
|
91
90
|
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
#
|
95
|
-
#
|
91
|
+
# Sidekiq.set_schedule('some_job', { :class => 'SomeJob',
|
92
|
+
# :every => '15mins',
|
93
|
+
# :queue => 'high',
|
94
|
+
# :args => '/tmp/poop' })
|
96
95
|
def set_schedule(name, config)
|
97
96
|
existing_config = get_schedule(name)
|
98
97
|
unless existing_config && existing_config == config
|
@@ -1,3 +1,3 @@
|
|
1
1
|
module SidekiqScheduler
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '0.6'
|
3
|
+
end
|
data/lib/sidekiq/scheduler.rb
CHANGED
@@ -111,13 +111,16 @@ module Sidekiq
|
|
111
111
|
|
112
112
|
# Enqueue a job based on a config hash
|
113
113
|
def self.enqueue_from_config(job_config)
|
114
|
-
|
115
|
-
args = args.is_a?(Hash) ? [args] : Array(args)
|
116
|
-
|
117
|
-
klass_name = job_config[:class] || job_config['class']
|
118
|
-
klass = klass_name.constantize rescue constantize(klass_name)
|
114
|
+
config = job_config.dup
|
119
115
|
|
120
|
-
|
116
|
+
config['class'] = if config['class'].is_a?(String)
|
117
|
+
config['class'].constantize
|
118
|
+
else
|
119
|
+
config['class']
|
120
|
+
end
|
121
|
+
config['args'] = Array(config['args'])
|
122
|
+
|
123
|
+
Sidekiq::Client.push(config)
|
121
124
|
end
|
122
125
|
|
123
126
|
def self.rufus_scheduler
|
@@ -162,5 +165,6 @@ module Sidekiq
|
|
162
165
|
self.scheduled_jobs.delete(name)
|
163
166
|
end
|
164
167
|
end
|
168
|
+
|
165
169
|
end
|
166
|
-
end
|
170
|
+
end
|
data/test/cli_test.rb
CHANGED
@@ -2,9 +2,12 @@ require 'test_helper'
|
|
2
2
|
require 'sidekiq-scheduler/cli'
|
3
3
|
require 'tempfile'
|
4
4
|
|
5
|
-
class CliTest <
|
5
|
+
class CliTest < Minitest::Test
|
6
|
+
|
6
7
|
describe 'with cli' do
|
8
|
+
|
7
9
|
before do
|
10
|
+
Celluloid.boot
|
8
11
|
@cli = Sidekiq::CLI.instance
|
9
12
|
end
|
10
13
|
|
@@ -17,5 +20,7 @@ class CliTest < MiniTest::Unit::TestCase
|
|
17
20
|
assert_equal 30, Sidekiq.options[:resolution]
|
18
21
|
end
|
19
22
|
end
|
23
|
+
|
20
24
|
end
|
25
|
+
|
21
26
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class ManagerTest <
|
3
|
+
class ManagerTest < Minitest::Test
|
4
4
|
describe 'Sidekiq::Scheduler' do
|
5
5
|
|
6
6
|
before do
|
@@ -15,35 +15,37 @@ class ManagerTest < MiniTest::Unit::TestCase
|
|
15
15
|
# The job should be loaded, since a missing rails_env means ALL envs.
|
16
16
|
ENV['RAILS_ENV'] = 'production'
|
17
17
|
config = {
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
'cron' => '* * * * *',
|
19
|
+
'class' => 'SomeRealClass',
|
20
|
+
'queue' => 'high',
|
21
|
+
'args' => '/tmp'
|
21
22
|
}
|
22
23
|
|
23
24
|
Sidekiq::Client.expects(:push).with(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
{
|
26
|
+
'cron' => '* * * * *',
|
27
|
+
'class' => SomeRealClass,
|
28
|
+
'queue' => 'high',
|
29
|
+
'args' => ['/tmp']
|
30
|
+
}
|
29
31
|
)
|
30
32
|
Sidekiq::Scheduler.enqueue_from_config(config)
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'enqueue_from_config respects queue params' do
|
34
36
|
config = {
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
'cron' => '* * * * *',
|
38
|
+
'class' => 'SomeIvarJob',
|
39
|
+
'queue' => 'high'
|
38
40
|
}
|
39
41
|
|
40
42
|
Sidekiq::Client.expects(:push).with(
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
{
|
44
|
+
'cron' => '* * * * *',
|
45
|
+
'class' => SomeIvarJob,
|
46
|
+
'args' => [],
|
47
|
+
'queue' => 'high'
|
48
|
+
}
|
47
49
|
)
|
48
50
|
|
49
51
|
Sidekiq::Scheduler.enqueue_from_config(config)
|
@@ -52,66 +54,65 @@ class ManagerTest < MiniTest::Unit::TestCase
|
|
52
54
|
it 'config makes it into the rufus_scheduler' do
|
53
55
|
assert_equal(0, Sidekiq::Scheduler.rufus_scheduler.all_jobs.size)
|
54
56
|
Sidekiq.schedule = {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
:some_ivar_job => {
|
58
|
+
'cron' => '* * * * *',
|
59
|
+
'class' => 'SomeIvarJob',
|
60
|
+
'args' => '/tmp'
|
61
|
+
}
|
60
62
|
}
|
61
63
|
|
62
|
-
|
63
64
|
Sidekiq::Scheduler.load_schedule!
|
64
65
|
|
65
66
|
assert_equal(1, Sidekiq::Scheduler.rufus_scheduler.all_jobs.size)
|
66
67
|
assert Sidekiq::Scheduler.scheduled_jobs.include?(:some_ivar_job)
|
67
68
|
end
|
68
69
|
|
70
|
+
# THIS
|
69
71
|
it 'can reload schedule' do
|
70
72
|
Sidekiq::Scheduler.dynamic = true
|
71
73
|
Sidekiq.schedule = {
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
74
|
+
:some_ivar_job => {
|
75
|
+
'cron' => '* * * * *',
|
76
|
+
'class' => 'SomeIvarJob',
|
77
|
+
'args' => '/tmp'
|
78
|
+
}
|
77
79
|
}
|
78
80
|
|
79
81
|
Sidekiq::Scheduler.load_schedule!
|
80
82
|
|
81
|
-
|
82
|
-
assert Sidekiq::Scheduler.scheduled_jobs.include?(:some_ivar_job)
|
83
|
+
assert Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job')
|
83
84
|
|
84
85
|
Sidekiq.redis { |r| r.del(:schedules) }
|
85
86
|
Sidekiq.redis do |r|
|
86
87
|
r.hset(
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
88
|
+
:schedules,
|
89
|
+
'some_ivar_job2',
|
90
|
+
MultiJson.encode(
|
91
|
+
{
|
92
|
+
'cron' => '* * * * *',
|
93
|
+
'class' => 'SomeIvarJob',
|
94
|
+
'args' => '/tmp/2'
|
95
|
+
}
|
96
|
+
)
|
96
97
|
)
|
97
98
|
end
|
98
99
|
|
99
100
|
Sidekiq::Scheduler.reload_schedule!
|
100
101
|
|
101
|
-
|
102
|
+
assert Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job')
|
103
|
+
assert Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job2')
|
102
104
|
|
103
105
|
assert_equal '/tmp/2', Sidekiq.schedule['some_ivar_job2']['args']
|
104
|
-
assert Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job2')
|
105
106
|
end
|
106
107
|
|
107
108
|
it 'load_schedule_job loads a schedule' do
|
108
109
|
Sidekiq::Scheduler.load_schedule_job(
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
'some_ivar_job',
|
111
|
+
{
|
112
|
+
'cron' => '* * * * *',
|
113
|
+
'class' => 'SomeIvarJob',
|
114
|
+
'args' => '/tmp'
|
115
|
+
}
|
115
116
|
)
|
116
117
|
|
117
118
|
assert_equal(1, Sidekiq::Scheduler.rufus_scheduler.all_jobs.size)
|
@@ -121,12 +122,12 @@ class ManagerTest < MiniTest::Unit::TestCase
|
|
121
122
|
|
122
123
|
it 'load_schedule_job with every with options' do
|
123
124
|
Sidekiq::Scheduler.load_schedule_job(
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
125
|
+
'some_ivar_job',
|
126
|
+
{
|
127
|
+
'every' => ['30s', {'first_in' => '60s'}],
|
128
|
+
'class' => 'SomeIvarJob',
|
129
|
+
'args' => '/tmp'
|
130
|
+
}
|
130
131
|
)
|
131
132
|
|
132
133
|
assert_equal(1, Sidekiq::Scheduler.rufus_scheduler.all_jobs.size)
|
@@ -137,12 +138,12 @@ class ManagerTest < MiniTest::Unit::TestCase
|
|
137
138
|
|
138
139
|
it 'load_schedule_job with cron with options' do
|
139
140
|
Sidekiq::Scheduler.load_schedule_job(
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
141
|
+
'some_ivar_job',
|
142
|
+
{
|
143
|
+
'cron' => ['* * * * *', {'allow_overlapping' => 'true'}],
|
144
|
+
'class' => 'SomeIvarJob',
|
145
|
+
'args' => '/tmp'
|
146
|
+
}
|
146
147
|
)
|
147
148
|
|
148
149
|
assert_equal(1, Sidekiq::Scheduler.rufus_scheduler.all_jobs.size)
|
@@ -153,11 +154,11 @@ class ManagerTest < MiniTest::Unit::TestCase
|
|
153
154
|
|
154
155
|
it 'does not load the schedule without cron' do
|
155
156
|
Sidekiq::Scheduler.load_schedule_job(
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
157
|
+
'some_ivar_job',
|
158
|
+
{
|
159
|
+
'class' => 'SomeIvarJob',
|
160
|
+
'args' => '/tmp'
|
161
|
+
}
|
161
162
|
)
|
162
163
|
|
163
164
|
assert_equal(0, Sidekiq::Scheduler.rufus_scheduler.all_jobs.size)
|
@@ -167,12 +168,12 @@ class ManagerTest < MiniTest::Unit::TestCase
|
|
167
168
|
|
168
169
|
it 'does not load the schedule with an empty cron' do
|
169
170
|
Sidekiq::Scheduler.load_schedule_job(
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
171
|
+
'some_ivar_job',
|
172
|
+
{
|
173
|
+
'cron' => '',
|
174
|
+
'class' => 'SomeIvarJob',
|
175
|
+
'args' => '/tmp'
|
176
|
+
}
|
176
177
|
)
|
177
178
|
|
178
179
|
assert_equal(0, Sidekiq::Scheduler.rufus_scheduler.all_jobs.size)
|
@@ -181,99 +182,46 @@ class ManagerTest < MiniTest::Unit::TestCase
|
|
181
182
|
end
|
182
183
|
|
183
184
|
it 'update_schedule' do
|
184
|
-
Sidekiq::Scheduler.dynamic = true
|
185
|
-
Sidekiq.schedule =
|
186
|
-
{
|
187
|
-
'some_ivar_job' => {'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp'},
|
188
|
-
'another_ivar_job' => {'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/5'},
|
189
|
-
'stay_put_job' => {'cron' => '* * * * *', 'class' => 'SomeJob', 'args' => '/tmp'}
|
190
|
-
}
|
191
|
-
|
192
|
-
Sidekiq::Scheduler.load_schedule!
|
193
|
-
|
194
|
-
Sidekiq.set_schedule(
|
195
|
-
'some_ivar_job',
|
196
|
-
{
|
197
|
-
'cron' => '* * * * *',
|
198
|
-
'class' => 'SomeIvarJob',
|
199
|
-
'args' => '/tmp/2'
|
200
|
-
}
|
201
|
-
)
|
202
|
-
Sidekiq.set_schedule(
|
203
|
-
'new_ivar_job',
|
204
|
-
{
|
205
|
-
'cron' => '* * * * *',
|
206
|
-
'class' => 'SomeJob',
|
207
|
-
'args' => '/tmp/3'
|
208
|
-
}
|
209
|
-
)
|
210
|
-
Sidekiq.set_schedule(
|
211
|
-
'stay_put_job',
|
212
|
-
{
|
213
|
-
'cron' => '* * * * *',
|
214
|
-
'class' => 'SomeJob',
|
215
|
-
'args' => '/tmp'
|
216
|
-
}
|
217
|
-
)
|
218
|
-
Sidekiq.remove_schedule('another_ivar_job')
|
219
|
-
|
220
|
-
Sidekiq::Scheduler.update_schedule
|
221
|
-
|
222
|
-
assert_equal(3, Sidekiq::Scheduler.rufus_scheduler.all_jobs.size)
|
223
|
-
assert_equal(3, Sidekiq::Scheduler.scheduled_jobs.size)
|
224
|
-
|
225
|
-
|
226
|
-
%w(some_ivar_job new_ivar_job stay_put_job).each do |job_name|
|
227
|
-
assert Sidekiq::Scheduler.scheduled_jobs.keys.include?(job_name)
|
228
|
-
assert Sidekiq.schedule.keys.include?(job_name)
|
229
|
-
end
|
230
|
-
assert !Sidekiq::Scheduler.scheduled_jobs.keys.include?('another_ivar_job')
|
231
|
-
assert !Sidekiq.schedule.keys.include?('another_ivar_job')
|
232
|
-
assert_equal 0, Sidekiq.redis { |r| r.scard(:schedules_changed) }
|
233
|
-
end
|
234
|
-
|
235
|
-
it 'update_schedule with mocks' do
|
236
185
|
Sidekiq::Scheduler.dynamic = true
|
237
186
|
Sidekiq.schedule = {
|
238
|
-
|
239
|
-
|
240
|
-
|
187
|
+
'some_ivar_job' => {'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp'},
|
188
|
+
'another_ivar_job' => {'cron' => '* * * * *', 'class' => 'SomeIvarJob', 'args' => '/tmp/5'},
|
189
|
+
'stay_put_job' => {'cron' => '* * * * *', 'class' => 'SomeJob', 'args' => '/tmp'}
|
241
190
|
}
|
242
191
|
|
243
192
|
Sidekiq::Scheduler.load_schedule!
|
244
193
|
|
245
|
-
Sidekiq::Scheduler.
|
246
|
-
Sidekiq::Scheduler.
|
194
|
+
Sidekiq::Scheduler.scheduled_jobs['some_ivar_job'].expects(:unschedule)
|
195
|
+
Sidekiq::Scheduler.scheduled_jobs['another_ivar_job'].expects(:unschedule)
|
247
196
|
|
248
197
|
Sidekiq.set_schedule(
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
198
|
+
'some_ivar_job',
|
199
|
+
{
|
200
|
+
'cron' => '* * * * *',
|
201
|
+
'class' => 'SomeIvarJob',
|
202
|
+
'args' => '/tmp/2'
|
203
|
+
}
|
255
204
|
)
|
256
205
|
Sidekiq.set_schedule(
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
206
|
+
'new_ivar_job',
|
207
|
+
{
|
208
|
+
'cron' => '* * * * *',
|
209
|
+
'class' => 'SomeJob',
|
210
|
+
'args' => '/tmp/3'
|
211
|
+
}
|
263
212
|
)
|
264
213
|
Sidekiq.set_schedule(
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
214
|
+
'stay_put_job',
|
215
|
+
{
|
216
|
+
'cron' => '* * * * *',
|
217
|
+
'class' => 'SomeJob',
|
218
|
+
'args' => '/tmp'
|
219
|
+
}
|
271
220
|
)
|
272
221
|
Sidekiq.remove_schedule('another_ivar_job')
|
273
222
|
|
274
223
|
Sidekiq::Scheduler.update_schedule
|
275
224
|
|
276
|
-
assert_equal(3, Sidekiq::Scheduler.scheduled_jobs.size)
|
277
225
|
%w(some_ivar_job new_ivar_job stay_put_job).each do |job_name|
|
278
226
|
assert Sidekiq::Scheduler.scheduled_jobs.keys.include?(job_name)
|
279
227
|
assert Sidekiq.schedule.keys.include?(job_name)
|
@@ -282,5 +230,6 @@ class ManagerTest < MiniTest::Unit::TestCase
|
|
282
230
|
assert !Sidekiq.schedule.keys.include?('another_ivar_job')
|
283
231
|
assert_equal 0, Sidekiq.redis { |r| r.scard(:schedules_changed) }
|
284
232
|
end
|
233
|
+
|
285
234
|
end
|
286
|
-
end
|
235
|
+
end
|