rekiq 0.7.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/example/test_app.rb +1 -1
- data/lib/rekiq/middleware/work_overseer.rb +7 -3
- data/lib/rekiq/scheduler.rb +2 -1
- data/lib/rekiq/version.rb +1 -1
- data/lib/rekiq/worker.rb +16 -17
- data/rekiq.gemspec +4 -2
- data/spec/factories/configuration.rb +4 -4
- data/spec/factories/job.rb +5 -5
- data/spec/rekiq/middleware/work_overseer_spec.rb +18 -10
- data/spec/rekiq/worker_spec.rb +6 -4
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 482599a4667b43c5690d7a4232e0ae3d87f2c4fd
|
4
|
+
data.tar.gz: 9964d52d551ed769dada46c3ab8427f77465c8ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34104c582240196d8effd91b0ea5ae48f9d43beb0e7fba9ba5fe8db2e93b17f4269488a947967f5f0f7ebb8d3bf43801e5239db29d8e1ff2ee8033b73e6b0132
|
7
|
+
data.tar.gz: 71f5c7c77a0934bea52bfba4f0913e3ef86260b1ba657e0cf28cce45d29b9e8933ca1803b29768f36422e497436e5b83bd8bb2525fa85438feea242e15c2b3f2
|
data/README.md
CHANGED
@@ -71,7 +71,7 @@ For our example we'll be using the gem [ice_cube](https://github.com/seejohnrun/
|
|
71
71
|
# now just start your worker
|
72
72
|
ExampleWorker.perform_recurringly(schedule, 'argument_1', 'argument_2')
|
73
73
|
|
74
|
-
|
74
|
+
And that's it! Now the worker will run every friday as 2am.
|
75
75
|
|
76
76
|
You can use your own schedule object, configure worker to schedule before or
|
77
77
|
after work is done, set a margin, and much more! So please feel free to check
|
@@ -79,7 +79,7 @@ after work is done, set a margin, and much more! So please feel free to check
|
|
79
79
|
|
80
80
|
## Contributing
|
81
81
|
|
82
|
-
1. Fork it ( https://github.com/
|
82
|
+
1. Fork it ( https://github.com/junhanamaki/rekiq/fork )
|
83
83
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
84
84
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
85
85
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/example/test_app.rb
CHANGED
@@ -9,7 +9,7 @@ require 'rekiq'
|
|
9
9
|
class TestWorker1
|
10
10
|
include Sidekiq::Worker
|
11
11
|
|
12
|
-
sidekiq_options queue: "rekiq_test_worker", retry:
|
12
|
+
sidekiq_options queue: "rekiq_test_worker", retry: 3
|
13
13
|
|
14
14
|
def perform(arg1, arg2)
|
15
15
|
puts "\n\nhello from TestWorker1, arg1 is #{arg1}, arg2 is #{arg2}" \
|
@@ -9,15 +9,19 @@ module Rekiq
|
|
9
9
|
include ::Sidekiq::Util
|
10
10
|
|
11
11
|
def call(worker, msg, queue)
|
12
|
-
return yield unless msg
|
12
|
+
return yield unless msg.key?('rq:job')
|
13
13
|
|
14
14
|
setup_vars(worker, msg, queue)
|
15
15
|
|
16
16
|
if !@canceller_name.nil? and
|
17
17
|
worker.send(@canceller_name, *@canceller_args)
|
18
|
-
|
18
|
+
return logger.info 'worker canceled by recurrence canceller'
|
19
19
|
end
|
20
20
|
|
21
|
+
return yield unless msg.key?('rq:schdlr')
|
22
|
+
|
23
|
+
msg.delete('rq:schdlr')
|
24
|
+
|
21
25
|
begin
|
22
26
|
reschedule unless @job.schedule_post_work?
|
23
27
|
yield
|
@@ -29,7 +33,7 @@ module Rekiq
|
|
29
33
|
protected
|
30
34
|
|
31
35
|
def setup_vars(worker, msg, queue)
|
32
|
-
@canceller_name = worker.
|
36
|
+
@canceller_name = worker.recurrence_canceller_name
|
33
37
|
@canceller_args = msg['rq:ca']
|
34
38
|
@worker_name = worker.class.name
|
35
39
|
@queue = queue
|
data/lib/rekiq/scheduler.rb
CHANGED
@@ -31,9 +31,10 @@ module Rekiq
|
|
31
31
|
'args' => @args,
|
32
32
|
'rq:job' => @job.to_array,
|
33
33
|
'rq:at' => @work_time.to_f,
|
34
|
+
'rq:schdlr' => nil
|
34
35
|
}.tap do |hash|
|
35
36
|
hash['rq:addon'] = @addon unless @addon.nil?
|
36
|
-
hash['rq:ca']
|
37
|
+
hash['rq:ca'] = @canceller_args unless @canceller_args.nil?
|
37
38
|
end
|
38
39
|
|
39
40
|
Sidekiq::Client.push(client_args)
|
data/lib/rekiq/version.rb
CHANGED
data/lib/rekiq/worker.rb
CHANGED
@@ -6,20 +6,14 @@ module Rekiq
|
|
6
6
|
module Worker
|
7
7
|
class Configuration
|
8
8
|
attr_accessor :shift, :schedule_post_work, :schedule_expired,
|
9
|
-
:expiration_margin, :addon, :
|
9
|
+
:expiration_margin, :addon, :recurrence_canceller_args
|
10
10
|
|
11
|
-
def
|
12
|
-
self.
|
11
|
+
def recurrence_canceller_args(*args)
|
12
|
+
self.recurrence_canceller_args = args
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
module ClassMethods
|
17
|
-
attr_reader :canceller_name
|
18
|
-
|
19
|
-
def rekiq_canceller(method_name)
|
20
|
-
@canceller_name = method_name
|
21
|
-
end
|
22
|
-
|
23
17
|
def perform_recurringly(schedule, *args)
|
24
18
|
@config = Configuration.new
|
25
19
|
yield @config if block_given?
|
@@ -40,7 +34,7 @@ module Rekiq
|
|
40
34
|
|
41
35
|
jid, work_time =
|
42
36
|
Rekiq::Scheduler
|
43
|
-
.new(name, queue, args, job, @config.addon, @config.
|
37
|
+
.new(name, queue, args, job, @config.addon, @config.recurrence_canceller_args)
|
44
38
|
.schedule
|
45
39
|
|
46
40
|
if jid.nil?
|
@@ -52,15 +46,20 @@ module Rekiq
|
|
52
46
|
jid
|
53
47
|
end
|
54
48
|
|
49
|
+
def recurrence_canceller_name
|
50
|
+
get_sidekiq_options['recurrence_canceller_name']
|
51
|
+
end
|
52
|
+
|
55
53
|
protected
|
56
54
|
|
57
55
|
def validate!
|
58
|
-
unless
|
59
|
-
self.method_defined?(
|
56
|
+
unless recurrence_canceller_name.nil? or
|
57
|
+
self.method_defined?(recurrence_canceller_name)
|
60
58
|
raise CancellerMethodMissing,
|
61
|
-
|
62
|
-
|
63
|
-
'remove
|
59
|
+
'recurrence canceller method name defined as ' \
|
60
|
+
"#{recurrence_canceller_name}, but worker does not have " \
|
61
|
+
'a method with that name, either remove definition or define ' \
|
62
|
+
'missing method'
|
64
63
|
end
|
65
64
|
end
|
66
65
|
end
|
@@ -78,8 +77,8 @@ module Sidekiq
|
|
78
77
|
base.extend(Rekiq::Worker::ClassMethods)
|
79
78
|
end
|
80
79
|
|
81
|
-
def
|
82
|
-
self.class.
|
80
|
+
def recurrence_canceller_name
|
81
|
+
self.class.recurrence_canceller_name
|
83
82
|
end
|
84
83
|
end
|
85
84
|
end
|
data/rekiq.gemspec
CHANGED
@@ -8,8 +8,10 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Rekiq::VERSION
|
9
9
|
spec.authors = ["junhanamaki"]
|
10
10
|
spec.email = ["jun.hanamaki@gmail.com"]
|
11
|
-
spec.summary = %q{
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Recurring worker extension for Sidekiq}
|
12
|
+
spec.description = %q{Rekiq extends Sidekiq so that we can schedule
|
13
|
+
recurring workers, check homepage for
|
14
|
+
more details.}
|
13
15
|
spec.homepage = "https://github.com/junhanamaki/rekiq"
|
14
16
|
spec.license = "MIT"
|
15
17
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
FactoryGirl.define do
|
2
2
|
factory :configuration, class: Rekiq::Configuration do
|
3
|
-
shift
|
4
|
-
schedule_post_work
|
5
|
-
expiration_margin
|
6
|
-
schedule_expired
|
3
|
+
shift [*-100..100].sample
|
4
|
+
schedule_post_work [true, false].sample
|
5
|
+
expiration_margin [*0..100].sample
|
6
|
+
schedule_expired [true, false].sample
|
7
7
|
end
|
8
8
|
end
|
data/spec/factories/job.rb
CHANGED
@@ -3,13 +3,13 @@ require 'ice_cube'
|
|
3
3
|
FactoryGirl.define do
|
4
4
|
factory :job, class: Rekiq::Job do
|
5
5
|
shift 0
|
6
|
-
schedule
|
6
|
+
schedule IceCube::Schedule.new(Time.now + 3600)
|
7
7
|
|
8
8
|
trait :randomized_attributes do
|
9
|
-
shift
|
10
|
-
schedule_post_work
|
11
|
-
schedule_expired
|
12
|
-
expiration_margin
|
9
|
+
shift [*0..100].sample
|
10
|
+
schedule_post_work [nil, false, true].sample
|
11
|
+
schedule_expired [nil, false, true].sample
|
12
|
+
expiration_margin [*0..100].sample
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -10,8 +10,8 @@ describe Rekiq::Middleware::WorkOverseer do
|
|
10
10
|
class WorkOverseerCancelTestWorker
|
11
11
|
include Sidekiq::Worker
|
12
12
|
|
13
|
-
sidekiq_options queue: 'work_overseer_test_worker'
|
14
|
-
|
13
|
+
sidekiq_options queue: 'work_overseer_test_worker',
|
14
|
+
recurrence_canceller_name: :cancel
|
15
15
|
|
16
16
|
def cancel(bool)
|
17
17
|
bool
|
@@ -24,12 +24,15 @@ describe Rekiq::Middleware::WorkOverseer do
|
|
24
24
|
let(:job) { build(:job, schedule: schedule) }
|
25
25
|
let(:overseer) { Rekiq::Middleware::WorkOverseer.new }
|
26
26
|
|
27
|
-
context 'worker does not have
|
27
|
+
context 'worker does not have recurrence_canceller_name set' do
|
28
28
|
let(:worker) { WorkOverseerTestWorker.new }
|
29
29
|
let(:queue) { WorkOverseerTestWorker.get_sidekiq_options['queue'] }
|
30
30
|
|
31
|
-
context 'msg with rq:job key (existing job)'
|
32
|
-
|
31
|
+
context 'msg with rq:job key (existing job), ' \
|
32
|
+
'with rq:schdlr key (value is irrelevant)' do
|
33
|
+
let(:msg) do
|
34
|
+
{ 'rq:job' => job.to_array, 'args' => args, 'rq:schdlr' => nil }
|
35
|
+
end
|
33
36
|
|
34
37
|
it 'yields once' do
|
35
38
|
expect do |b|
|
@@ -42,6 +45,12 @@ describe Rekiq::Middleware::WorkOverseer do
|
|
42
45
|
|
43
46
|
expect(WorkOverseerTestWorker.jobs.count).to eq(1)
|
44
47
|
end
|
48
|
+
|
49
|
+
it 'removes key rq:schdlr from message after invocation' do
|
50
|
+
overseer.call(worker, msg, queue) {}
|
51
|
+
|
52
|
+
expect(msg.key?('rq:schdlr')).to eq(false)
|
53
|
+
end
|
45
54
|
end
|
46
55
|
|
47
56
|
context 'msg without rq:job key' do
|
@@ -54,9 +63,8 @@ describe Rekiq::Middleware::WorkOverseer do
|
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
57
|
-
context 'msg
|
58
|
-
let(:msg) { { 'rq:job' => job.to_array, '
|
59
|
-
'args' => args } }
|
66
|
+
context 'msg without rq:schdlr and rq:job (existing job)' do
|
67
|
+
let(:msg) { { 'rq:job' => job.to_array, 'args' => args } }
|
60
68
|
|
61
69
|
it 'yields once' do
|
62
70
|
expect do |b|
|
@@ -64,7 +72,7 @@ describe Rekiq::Middleware::WorkOverseer do
|
|
64
72
|
end.to yield_control.once
|
65
73
|
end
|
66
74
|
|
67
|
-
it 'does not schedule work' do
|
75
|
+
it 'does not schedule next work' do
|
68
76
|
overseer.call(worker, msg, queue) {}
|
69
77
|
|
70
78
|
expect(WorkOverseerTestWorker.jobs.count).to eq(0)
|
@@ -72,7 +80,7 @@ describe Rekiq::Middleware::WorkOverseer do
|
|
72
80
|
end
|
73
81
|
end
|
74
82
|
|
75
|
-
context 'worker has
|
83
|
+
context 'worker has recurrence_canceller_name method set' do
|
76
84
|
let(:worker) { WorkOverseerCancelTestWorker.new }
|
77
85
|
let(:queue) { WorkOverseerCancelTestWorker.get_sidekiq_options['queue'] }
|
78
86
|
|
data/spec/rekiq/worker_spec.rb
CHANGED
@@ -9,12 +9,12 @@ describe Rekiq::Worker do
|
|
9
9
|
|
10
10
|
class CancellerUndefinedExampleWorker
|
11
11
|
include Sidekiq::Worker
|
12
|
-
|
12
|
+
sidekiq_options recurrence_canceller_name: :cancel
|
13
13
|
end
|
14
14
|
|
15
15
|
class CancellerDefinedExampleWorker
|
16
16
|
include Sidekiq::Worker
|
17
|
-
|
17
|
+
sidekiq_options recurrence_canceller_name: :cancel
|
18
18
|
|
19
19
|
def cancel
|
20
20
|
end
|
@@ -45,7 +45,8 @@ describe Rekiq::Worker do
|
|
45
45
|
let(:time) { Time.now + 3600 }
|
46
46
|
let(:schedule) { IceCube::Schedule.new(time) }
|
47
47
|
|
48
|
-
context 'for worker with
|
48
|
+
context 'for worker with recurrence_canceller_name set with ' \
|
49
|
+
'non defined method' do
|
49
50
|
before do
|
50
51
|
begin
|
51
52
|
@jid =
|
@@ -65,7 +66,8 @@ describe Rekiq::Worker do
|
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
context 'for worker with
|
69
|
+
context 'for worker with recurrence_canceller_name set with ' \
|
70
|
+
'defined method' do
|
69
71
|
before do
|
70
72
|
@jid = CancellerDefinedExampleWorker.perform_recurringly(schedule)
|
71
73
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rekiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- junhanamaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,7 +122,10 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '3.2'
|
125
|
-
description:
|
125
|
+
description: |-
|
126
|
+
Rekiq extends Sidekiq so that we can schedule
|
127
|
+
recurring workers, check homepage for
|
128
|
+
more details.
|
126
129
|
email:
|
127
130
|
- jun.hanamaki@gmail.com
|
128
131
|
executables: []
|
@@ -183,7 +186,7 @@ rubyforge_project:
|
|
183
186
|
rubygems_version: 2.2.2
|
184
187
|
signing_key:
|
185
188
|
specification_version: 4
|
186
|
-
summary:
|
189
|
+
summary: Recurring worker extension for Sidekiq
|
187
190
|
test_files:
|
188
191
|
- spec/factories/configuration.rb
|
189
192
|
- spec/factories/job.rb
|