resque-multi-step 2.0.6 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/resque/plugins/multi_step_task.rb +10 -26
- data/resque-multi-step.gemspec +2 -2
- data/spec/acceptance/job_handling_spec.rb +43 -0
- data/spec/resque/plugins/multi_step_task_spec.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df39997beea740b98549e87d7405f1a17c95dd3b
|
4
|
+
data.tar.gz: 72cc72d49e4efc972b766c8666396c4f8cece360
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97523b06a455bebe45719e257107cc135d795cc3cee846646d4ae32038671dfff9b330ad96901117e6949de89e2b796e3c8a49aec9314a5843c9526eaa509e64
|
7
|
+
data.tar.gz: 89f819793f82d9eb02cadc2007fde22a9736c336c24dad5b06386ebcd9eba46a35032c8e603eae65aadb10e411c210e8d02e33c6194a695fb9c9941953fa4933
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.8
|
@@ -69,7 +69,7 @@ module Resque
|
|
69
69
|
mst.finalizable!
|
70
70
|
end
|
71
71
|
|
72
|
-
mst
|
72
|
+
mst
|
73
73
|
end
|
74
74
|
|
75
75
|
# Prevent calling MultiStepTask.new
|
@@ -160,7 +160,6 @@ module Resque
|
|
160
160
|
include Constantization
|
161
161
|
|
162
162
|
attr_reader :task_id
|
163
|
-
attr_reader :started
|
164
163
|
attr_accessor :logger
|
165
164
|
|
166
165
|
extend AtomicCounters
|
@@ -179,8 +178,7 @@ module Resque
|
|
179
178
|
# @param [String] task_id The UUID of the group of interest.
|
180
179
|
def initialize(task_id)
|
181
180
|
@task_id = task_id
|
182
|
-
|
183
|
-
redis.set 'start-time', Time.now.to_i
|
181
|
+
redis.setnx 'start-time', Time.now.to_i
|
184
182
|
end
|
185
183
|
|
186
184
|
def logger
|
@@ -217,8 +215,11 @@ module Resque
|
|
217
215
|
increment_normal_job_count
|
218
216
|
logger.debug("[Resque Multi-Step-Task] Adding #{job_type} job for #{task_id} (args: #{args})")
|
219
217
|
|
220
|
-
|
221
|
-
|
218
|
+
if synchronous?
|
219
|
+
self.class.perform(task_id, job_type.to_s, *args)
|
220
|
+
else
|
221
|
+
Resque::Job.create(queue_name, self.class, task_id, job_type.to_s, *args)
|
222
|
+
end
|
222
223
|
end
|
223
224
|
|
224
225
|
# Finalization jobs are performed after all the normal jobs
|
@@ -234,25 +235,6 @@ module Resque
|
|
234
235
|
redis.rpush 'finalize_jobs', Yajl::Encoder.encode([job_type.to_s, *args])
|
235
236
|
end
|
236
237
|
|
237
|
-
def start
|
238
|
-
unless started
|
239
|
-
while nrm_job_info = redis.lpop('normal_jobs')
|
240
|
-
job_class, *args = Yajl::Parser.parse(nrm_job_info)
|
241
|
-
run_job(job_class, *args)
|
242
|
-
end
|
243
|
-
@started = true
|
244
|
-
end
|
245
|
-
self
|
246
|
-
end
|
247
|
-
|
248
|
-
def run_job(job_type, *args)
|
249
|
-
if synchronous?
|
250
|
-
self.class.perform(task_id, job_type.to_s, *args)
|
251
|
-
else
|
252
|
-
Resque::Job.create(queue_name, self.class, task_id, job_type.to_s, *args)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
238
|
# A multi-step task is finalizable when all the normal jobs (see
|
257
239
|
# #add_job) have been registered. Finalization jobs will not be
|
258
240
|
# executed until the task becomes finalizable regardless of the
|
@@ -270,7 +252,9 @@ module Resque
|
|
270
252
|
# finalization happens after normal jobs, but in the wierd case where
|
271
253
|
# there are only finalization jobs, we need to add a fake normal job
|
272
254
|
# that just kicks off the finalization process
|
273
|
-
|
255
|
+
#
|
256
|
+
# due to race conditions, always assure finalization - DCM
|
257
|
+
assure_finalization #if normal_job_count == 0
|
274
258
|
end
|
275
259
|
end
|
276
260
|
|
data/resque-multi-step.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "resque-multi-step"
|
8
|
-
s.version = "2.0.
|
8
|
+
s.version = "2.0.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Peter Williams", "Morgan Whitney", "Cameron Mauch"]
|
12
|
-
s.date = "2014-09-
|
12
|
+
s.date = "2014-09-18"
|
13
13
|
s.description = "Provides multi-step tasks with finalization and progress tracking"
|
14
14
|
s.email = "pezra@barelyenough.org"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -168,3 +168,46 @@ describe "Acceptance: Finalization always runs" do
|
|
168
168
|
Resque.redis.get("testing counter").to_i.should == 3
|
169
169
|
end
|
170
170
|
end
|
171
|
+
|
172
|
+
describe "Acceptance: Finalization always runs without block" do
|
173
|
+
let(:task) do
|
174
|
+
Resque::Plugins::MultiStepTask.create("testing")
|
175
|
+
end
|
176
|
+
|
177
|
+
before do
|
178
|
+
Resque.redis.del "testing"
|
179
|
+
task
|
180
|
+
task.add_job MultiStepAcceptance::CounterJob, "testing counter"
|
181
|
+
task.add_job MultiStepAcceptance::CounterJob, "testing counter"
|
182
|
+
task.add_finalization_job MultiStepAcceptance::CounterJob, "testing counter"
|
183
|
+
sleep 1
|
184
|
+
task.finalizable!
|
185
|
+
sleep 1
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should run normal jobs and finalization job' do
|
189
|
+
Resque.redis.get("testing counter").to_i.should == 3
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "Acceptance: add job to multi step task via find" do
|
194
|
+
let(:task) do
|
195
|
+
Resque::Plugins::MultiStepTask.create("testing") do |task|
|
196
|
+
task.add_job MultiStepAcceptance::CounterJob, "testing add job"
|
197
|
+
task.add_job MultiStepAcceptance::WaitJob, 2
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
before do
|
202
|
+
Resque.redis.del "testing"
|
203
|
+
task
|
204
|
+
sleep 1
|
205
|
+
task2 = Resque::Plugins::MultiStepTask.find(task.task_id)
|
206
|
+
task2.add_job MultiStepAcceptance::CounterJob, "testing add job"
|
207
|
+
sleep 1
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should run added jobs' do
|
211
|
+
Resque.redis.get("testing add job").to_i.should == 2
|
212
|
+
end
|
213
|
+
end
|
@@ -44,7 +44,7 @@ module Resque::Plugins
|
|
44
44
|
end
|
45
45
|
|
46
46
|
describe MultiStepTask do
|
47
|
-
let(:task) {MultiStepTask.create("some-task")
|
47
|
+
let(:task) {MultiStepTask.create("some-task")}
|
48
48
|
|
49
49
|
it "allows jobs to be added to task" do
|
50
50
|
lambda {
|
@@ -57,6 +57,11 @@ module Resque::Plugins
|
|
57
57
|
task.add_job(TestJob)
|
58
58
|
end
|
59
59
|
|
60
|
+
it "queues job when added to async task obtained via find" do
|
61
|
+
Resque::Job.should_receive(:create).with(task.queue_name, Resque::Plugins::MultiStepTask, task.task_id, 'TestJob')
|
62
|
+
Resque::Plugins::MultiStepTask.find(task.task_id).add_job(TestJob)
|
63
|
+
end
|
64
|
+
|
60
65
|
it "allows finalization jobs to be added" do
|
61
66
|
task.add_finalization_job(TestJob)
|
62
67
|
end
|
@@ -86,7 +91,7 @@ module Resque::Plugins
|
|
86
91
|
end
|
87
92
|
|
88
93
|
describe MultiStepTask, "synchronous mode" do
|
89
|
-
let(:task){MultiStepTask.create("some-task")
|
94
|
+
let(:task){MultiStepTask.create("some-task")}
|
90
95
|
|
91
96
|
before do
|
92
97
|
MultiStepTask.mode = :sync
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-multi-step
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Williams
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-09-
|
13
|
+
date: 2014-09-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: resque-multi-step
|