rekiq 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c35103e24fdf19a9103b5413045b7b9519f31b5c
4
- data.tar.gz: d370ec60d8dfa653b1fc2baab31b4bc9e63ec459
3
+ metadata.gz: bf6b35a349d92b73f219e0d576bc246eb57447f5
4
+ data.tar.gz: b26a1901ec408176fedc25be6a51f66d5849bd59
5
5
  SHA512:
6
- metadata.gz: 8cce22c704902a039b2dfdf721109c292199310a1bcab75398e4d3bcaa2c4cee1109f922ab34f85c59d8d3fbdf61fac02701091dde78f3709f56bbfade159205
7
- data.tar.gz: afd6108ae9af9a7285b8aa8afc7ec4af58892d0dcba5c71e1208150c36169230e6cb58207885e5aa889a7611e8b736c932157a97b8e3e23c38e13711992497bf
6
+ metadata.gz: d9a7e979b1f492540c788747b3dd7854ed3f27b1567bec4c15d568c65fd7df6715a7745c77d335bab19a8438e27b6f49ce8cff9596a891c87eedb357b05c3cd0
7
+ data.tar.gz: 491e3f5219bc3e0bae2ad6e725a3af8ad8844a0d324059d7cc7e817515f01617e861cac634a9cf7b472d334d6f43239b7fe74164a9dd0de850ef0ae6e8f1a036
@@ -17,6 +17,8 @@ module Rekiq
17
17
  @queue = queue
18
18
  @contract = Contract.from_hash(msg['rq:ctr'])
19
19
 
20
+ set_rekiq_worker_attributes
21
+
20
22
  if cancel_worker?
21
23
  return logger.info "worker #{@worker_name} was canceled"
22
24
  end
@@ -37,11 +39,17 @@ module Rekiq
37
39
 
38
40
  protected
39
41
 
42
+ def set_rekiq_worker_attributes
43
+ @worker.scheduled_work_time = Time.at(@msg['rq:at'].to_f).utc
44
+ @worker.estimated_next_work_time =
45
+ @contract.next_work_time(@worker.scheduled_work_time)
46
+ end
47
+
40
48
  def cancel_worker?
41
49
  @worker.cancel_rekiq_worker?(*@contract.cancel_args)
42
50
  end
43
51
 
44
- def reschedule
52
+ def reschedule()
45
53
  jid, work_time =
46
54
  Rekiq::Scheduler
47
55
  .new(@worker_name, @queue, @msg['args'], @contract)
data/lib/rekiq/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rekiq
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/rekiq/worker.rb CHANGED
@@ -66,7 +66,7 @@ end
66
66
 
67
67
  module Sidekiq
68
68
  module Worker
69
- attr_accessor :scheduled_work_time
69
+ attr_accessor :scheduled_work_time, :estimated_next_work_time
70
70
 
71
71
  original_included_method = method(:included)
72
72
 
data/lib/rekiq.rb CHANGED
@@ -12,11 +12,9 @@ end
12
12
 
13
13
  require 'rekiq/worker'
14
14
  require 'rekiq/middleware/work_overseer'
15
- require 'rekiq/middleware/utils'
16
15
 
17
16
  Sidekiq.configure_server do |config|
18
17
  config.server_middleware do |chain|
19
- chain.add Rekiq::Middleware::Utils
20
18
  chain.add Rekiq::Middleware::WorkOverseer
21
19
  end
22
20
  end
@@ -20,21 +20,34 @@ describe Rekiq::Middleware::WorkOverseer do
20
20
 
21
21
  describe '#call' do
22
22
  let(:args) { [] }
23
- let(:schedule) { IceCube::Schedule.new(Time.new + 3600) }
23
+ let(:schedule) do
24
+ IceCube::Schedule.new(Time.new + 3600) do |s|
25
+ s.rrule IceCube::Rule.daily
26
+ end
27
+ end
24
28
  let(:overseer) { Rekiq::Middleware::WorkOverseer.new }
25
29
  let(:cancel_args) { nil }
26
30
  let(:contract) do
27
31
  build :contract, schedule: schedule, cancel_args: cancel_args
28
32
  end
33
+ let(:scheduled_work_time) { Time.at(Time.now.to_f) }
34
+
35
+ before { overseer.call(worker, msg, queue) {} rescue nil }
29
36
 
30
37
  context 'worker without rekiq_cancel_method configured' do
31
38
  let(:worker) { WorkOverseerTestWorker.new }
32
39
  let(:queue) { WorkOverseerTestWorker.get_sidekiq_options['queue'] }
33
40
 
34
41
  context 'msg with rq:ctr key (existing contract), ' \
35
- 'with rq:sdl key (value is irrelevant)' do
42
+ 'with rq:sdl key (value is irrelevant), ' \
43
+ 'with rq:at key' do
36
44
  let(:msg) do
37
- { 'rq:ctr' => contract.to_hash, 'args' => args, 'rq:sdl' => nil }
45
+ {
46
+ 'rq:ctr' => contract.to_hash,
47
+ 'args' => args,
48
+ 'rq:sdl' => nil,
49
+ 'rq:at' => scheduled_work_time.to_f
50
+ }
38
51
  end
39
52
 
40
53
  it 'yields once' do
@@ -44,14 +57,19 @@ describe Rekiq::Middleware::WorkOverseer do
44
57
  end
45
58
 
46
59
  it 'schedules worker' do
47
- overseer.call(worker, msg, queue) {}
48
-
49
60
  expect(WorkOverseerTestWorker.jobs.count).to eq(1)
50
61
  end
51
62
 
52
- it 'removes key rq:sdl from message after invocation' do
53
- overseer.call(worker, msg, queue) {}
63
+ it 'sets scheduled_work_time attribute in worker' do
64
+ expect(worker.scheduled_work_time).to eq(scheduled_work_time.utc)
65
+ end
54
66
 
67
+ it 'sets estimated_next_work_time attribute in worker' do
68
+ expect(worker.estimated_next_work_time).to \
69
+ eq(schedule.next_occurrence)
70
+ end
71
+
72
+ it 'removes key rq:sdl from message after invocation' do
55
73
  expect(msg.key?('rq:sdl')).to eq(false)
56
74
  end
57
75
  end
@@ -66,14 +84,22 @@ describe Rekiq::Middleware::WorkOverseer do
66
84
  end
67
85
 
68
86
  it 'does not schedule worker' do
69
- overseer.call(worker, msg, queue) {}
70
-
71
87
  expect(WorkOverseerTestWorker.jobs.count).to eq(0)
72
88
  end
89
+
90
+ it 'scheduled_work_time in worker is unchanged (nil)' do
91
+ expect(worker.scheduled_work_time).to be_nil
92
+ end
73
93
  end
74
94
 
75
- context 'msg without key rq:sdl but with key rq:ctr' do
76
- let(:msg) { { 'rq:ctr' => contract.to_hash, 'args' => args } }
95
+ context 'msg without key rq:sdl but with key rq:ctr and rq:at' do
96
+ let(:msg) do
97
+ {
98
+ 'rq:ctr' => contract.to_hash,
99
+ 'args' => args,
100
+ 'rq:at' => scheduled_work_time.to_f
101
+ }
102
+ end
77
103
 
78
104
  it 'yields once' do
79
105
  expect do |b|
@@ -82,8 +108,6 @@ describe Rekiq::Middleware::WorkOverseer do
82
108
  end
83
109
 
84
110
  it 'does not schedule next work' do
85
- overseer.call(worker, msg, queue) {}
86
-
87
111
  expect(WorkOverseerTestWorker.jobs.count).to eq(0)
88
112
  end
89
113
  end
@@ -93,9 +117,16 @@ describe Rekiq::Middleware::WorkOverseer do
93
117
  let(:worker) { WorkOverseerCancelTestWorker.new }
94
118
  let(:queue) { WorkOverseerCancelTestWorker.get_sidekiq_options['queue'] }
95
119
 
96
- context 'msg with keys rc:ctr and rc:sdl' do
120
+ context 'msg with rq:ctr key (existing contract), ' \
121
+ 'with rq:sdl key (value is irrelevant), ' \
122
+ 'with rq:at key' do
97
123
  let(:msg) do
98
- { 'rq:ctr' => contract.to_hash, 'args' => args, 'rq:sdl' => nil }
124
+ {
125
+ 'rq:ctr' => contract.to_hash,
126
+ 'args' => args,
127
+ 'rq:sdl' => nil,
128
+ 'rq:at' => scheduled_work_time.to_f
129
+ }
99
130
  end
100
131
 
101
132
  context 'work is cancelled by cancel method' do
@@ -108,8 +139,6 @@ describe Rekiq::Middleware::WorkOverseer do
108
139
  end
109
140
 
110
141
  it 'does not schedule next work' do
111
- overseer.call(worker, msg, queue) {}
112
-
113
142
  expect(WorkOverseerCancelTestWorker.jobs.count).to eq(0)
114
143
  end
115
144
  end
@@ -124,16 +153,16 @@ describe Rekiq::Middleware::WorkOverseer do
124
153
  end
125
154
 
126
155
  it 'it schedules work' do
127
- overseer.call(worker, msg, queue) {}
128
-
129
156
  expect(WorkOverseerCancelTestWorker.jobs.count).to eq(1)
130
157
  end
131
158
 
132
159
  it 'removes key rq:sdl from message after invocation' do
133
- overseer.call(worker, msg, queue) {}
134
-
135
160
  expect(msg.key?('rq:sdl')).to eq(false)
136
161
  end
162
+
163
+ it 'sets scheduled_work_time attribute in worker' do
164
+ expect(worker.scheduled_work_time).to eq(scheduled_work_time.utc)
165
+ end
137
166
  end
138
167
 
139
168
  context 'contract with incorrect arity of cancel_args' do
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: 1.0.0
4
+ version: 1.1.0
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-02 00:00:00.000000000 Z
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,7 +132,6 @@ files:
132
132
  - lib/rekiq/configuration.rb
133
133
  - lib/rekiq/contract.rb
134
134
  - lib/rekiq/exceptions.rb
135
- - lib/rekiq/middleware/utils.rb
136
135
  - lib/rekiq/middleware/work_overseer.rb
137
136
  - lib/rekiq/scheduler.rb
138
137
  - lib/rekiq/validator.rb
@@ -143,7 +142,6 @@ files:
143
142
  - spec/factories/contract.rb
144
143
  - spec/rekiq/configuration_spec.rb
145
144
  - spec/rekiq/contract_spec.rb
146
- - spec/rekiq/middleware/utils_spec.rb
147
145
  - spec/rekiq/middleware/work_overseer_spec.rb
148
146
  - spec/rekiq/scheduler_spec.rb
149
147
  - spec/rekiq/worker_spec.rb
@@ -177,7 +175,6 @@ test_files:
177
175
  - spec/factories/contract.rb
178
176
  - spec/rekiq/configuration_spec.rb
179
177
  - spec/rekiq/contract_spec.rb
180
- - spec/rekiq/middleware/utils_spec.rb
181
178
  - spec/rekiq/middleware/work_overseer_spec.rb
182
179
  - spec/rekiq/scheduler_spec.rb
183
180
  - spec/rekiq/worker_spec.rb
@@ -1,13 +0,0 @@
1
- module Rekiq
2
- module Middleware
3
- class Utils
4
- def call(worker, msg, queue)
5
- if msg.key?('rq:at')
6
- worker.scheduled_work_time = Time.at(msg['rq:at'].to_f).utc
7
- end
8
-
9
- yield
10
- end
11
- end
12
- end
13
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Rekiq::Middleware::Utils do
4
- class UtilsTestWorker
5
- include Sidekiq::Worker
6
- end
7
-
8
- describe '#call' do
9
- let(:worker) { UtilsTestWorker.new }
10
- let(:queue) { UtilsTestWorker.get_sidekiq_options['queue'] }
11
- let(:utils) { Rekiq::Middleware::Utils.new }
12
- let(:scheduled_work_time) { Time.at(Time.now.to_f) }
13
-
14
- context 'worker responds to scheduled_work_time' do
15
- context 'msg hash contains keys rq:ctr and rq:at' do
16
- let(:msg) { { 'rq:ctr' => nil, 'rq:at' => scheduled_work_time.to_f } }
17
-
18
- it 'yields passed block' do
19
- expect do |b|
20
- utils.call(worker, msg, queue, &b)
21
- end.to yield_control.once
22
- end
23
-
24
- it 'sets scheduled_work_time attribute in worker' do
25
- utils.call(worker, msg, queue) {}
26
-
27
- expect(worker.scheduled_work_time).to eq(scheduled_work_time.utc)
28
- end
29
- end
30
-
31
- context 'msg has no key' do
32
- let(:msg) { {} }
33
-
34
- it 'yields passed block' do
35
- expect do |b|
36
- utils.call(worker, msg, queue, &b)
37
- end.to yield_control.once
38
- end
39
-
40
- it 'scheduled_work_time is unchanged (nil)' do
41
- expect(worker.scheduled_work_time).to be_nil
42
- end
43
- end
44
- end
45
- end
46
- end