resque-multi-step 2.0.3 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6d2c398ee76b64007f81d35964f4ac066bdc107
4
+ data.tar.gz: 6e37fc56ecc6b3de66fb723bad899862116fd420
5
+ SHA512:
6
+ metadata.gz: f57191578c45b3c7e8c7a8d6c0eebf69e60a3769472ef1e2b701ef3bb671e5cc20005b6323c7f331cdafcc5fc84c675e8fc90b28cad86a80c9a7552daecc23a5
7
+ data.tar.gz: 166077bb0374f0c0f7f70ead61dea736c52985aea7dbee361a3759be8b04cac3294a64feb1214171669beff48e5284ee20a5942d8f0ccb3ba8a019a5534c7a98
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rake'
4
+ gem 'jeweler'
5
+
3
6
  # Specify your gem's dependencies in resque-job-logger.gemspec
4
7
  gemspec
@@ -11,12 +11,51 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
+ addressable (2.3.6)
15
+ builder (3.2.2)
14
16
  diff-lcs (1.2.2)
17
+ faraday (0.8.9)
18
+ multipart-post (~> 1.2.0)
19
+ git (1.2.8)
20
+ github_api (0.10.2)
21
+ addressable
22
+ faraday (~> 0.8.7)
23
+ hashie (>= 1.2)
24
+ multi_json (~> 1.4)
25
+ nokogiri (~> 1.6.0)
26
+ oauth2
27
+ hashie (3.3.1)
28
+ highline (1.6.21)
29
+ jeweler (2.0.1)
30
+ builder
31
+ bundler (>= 1.0)
32
+ git (>= 1.2.5)
33
+ github_api
34
+ highline (>= 1.6.15)
35
+ nokogiri (>= 1.5.10)
36
+ rake
37
+ rdoc
38
+ json (1.8.1)
39
+ jwt (1.0.0)
40
+ mini_portile (0.6.0)
15
41
  mono_logger (1.0.0)
16
42
  multi_json (1.7.2)
43
+ multi_xml (0.5.5)
44
+ multipart-post (1.2.0)
45
+ nokogiri (1.6.3.1)
46
+ mini_portile (= 0.6.0)
47
+ oauth2 (1.0.0)
48
+ faraday (>= 0.8, < 0.10)
49
+ jwt (~> 1.0)
50
+ multi_json (~> 1.3)
51
+ multi_xml (~> 0.5)
52
+ rack (~> 1.2)
17
53
  rack (1.5.2)
18
54
  rack-protection (1.5.0)
19
55
  rack
56
+ rake (10.3.2)
57
+ rdoc (4.1.1)
58
+ json (~> 1.4)
20
59
  redis (3.0.3)
21
60
  redis-namespace (1.2.1)
22
61
  redis (~> 3.0.0)
@@ -49,5 +88,7 @@ PLATFORMS
49
88
  ruby
50
89
 
51
90
  DEPENDENCIES
91
+ jeweler
92
+ rake
52
93
  resque-multi-step!
53
94
  rspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.3
1
+ 2.0.4
@@ -30,9 +30,7 @@ module Resque
30
30
 
31
31
  # A bit of randomness to ensure tasks are uniquely identified.
32
32
  def nonce
33
- nonce = ""
34
- 5.times{nonce << NONCE_CHARS[rand(NONCE_CHARS.length)]}
35
- nonce
33
+ 5.times.map{NONCE_CHARS.sample}.join
36
34
  end
37
35
 
38
36
  # A redis client suitable for storing global mutli-step task info.
@@ -66,7 +64,6 @@ module Resque
66
64
  mst = new(task_id)
67
65
  mst.nuke
68
66
  redis.sadd("active-tasks", task_id)
69
- redis.sismember("active-tasks", task_id)
70
67
  if block_given?
71
68
  yield mst
72
69
  mst.finalizable!
@@ -163,6 +160,7 @@ module Resque
163
160
  include Constantization
164
161
 
165
162
  attr_reader :task_id
163
+ attr_reader :started
166
164
  attr_accessor :logger
167
165
 
168
166
  extend AtomicCounters
@@ -181,6 +179,7 @@ module Resque
181
179
  # @param [String] task_id The UUID of the group of interest.
182
180
  def initialize(task_id)
183
181
  @task_id = task_id
182
+ @started = false
184
183
  redis.set 'start-time', Time.now.to_i
185
184
  end
186
185
 
@@ -218,11 +217,8 @@ module Resque
218
217
  increment_normal_job_count
219
218
  logger.debug("[Resque Multi-Step-Task] Adding #{job_type} job for #{task_id} (args: #{args})")
220
219
 
221
- if synchronous?
222
- self.class.perform(task_id, job_type.to_s, *args)
223
- else
224
- Resque::Job.create(queue_name, self.class, task_id, job_type.to_s, *args)
225
- end
220
+ redis.rpush 'normal_jobs', Yajl::Encoder.encode([job_type.to_s, *args])
221
+ run_job job_type, *args if started
226
222
  end
227
223
 
228
224
  # Finalization jobs are performed after all the normal jobs
@@ -238,6 +234,25 @@ module Resque
238
234
  redis.rpush 'finalize_jobs', Yajl::Encoder.encode([job_type.to_s, *args])
239
235
  end
240
236
 
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
+
241
256
  # A multi-step task is finalizable when all the normal jobs (see
242
257
  # #add_job) have been registered. Finalization jobs will not be
243
258
  # executed until the task becomes finalizable regardless of the
@@ -257,6 +272,7 @@ module Resque
257
272
  # that just kicks off the finalization process
258
273
  assure_finalization if normal_job_count == 0
259
274
  end
275
+ start
260
276
  end
261
277
 
262
278
  def assure_finalization
@@ -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.3"
8
+ s.version = "2.0.4"
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"]
12
- s.date = "2014-02-05"
12
+ s.date = "2014-09-09"
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 = [
@@ -53,8 +53,6 @@ Gem::Specification.new do |s|
53
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
54
  s.add_runtime_dependency(%q<resque-multi-step>, [">= 0"])
55
55
  s.add_development_dependency(%q<rspec>, [">= 0"])
56
- s.add_development_dependency(%q<rspec>, [">= 0"])
57
- s.add_development_dependency(%q<rspec>, [">= 0"])
58
56
  s.add_runtime_dependency(%q<redis-namespace>, [">= 0"])
59
57
  s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
60
58
  s.add_runtime_dependency(%q<resque>, [">= 0"])
@@ -62,8 +60,6 @@ Gem::Specification.new do |s|
62
60
  else
63
61
  s.add_dependency(%q<resque-multi-step>, [">= 0"])
64
62
  s.add_dependency(%q<rspec>, [">= 0"])
65
- s.add_dependency(%q<rspec>, [">= 0"])
66
- s.add_dependency(%q<rspec>, [">= 0"])
67
63
  s.add_dependency(%q<redis-namespace>, [">= 0"])
68
64
  s.add_dependency(%q<yajl-ruby>, [">= 0"])
69
65
  s.add_dependency(%q<resque>, [">= 0"])
@@ -72,8 +68,6 @@ Gem::Specification.new do |s|
72
68
  else
73
69
  s.add_dependency(%q<resque-multi-step>, [">= 0"])
74
70
  s.add_dependency(%q<rspec>, [">= 0"])
75
- s.add_dependency(%q<rspec>, [">= 0"])
76
- s.add_dependency(%q<rspec>, [">= 0"])
77
71
  s.add_dependency(%q<redis-namespace>, [">= 0"])
78
72
  s.add_dependency(%q<yajl-ruby>, [">= 0"])
79
73
  s.add_dependency(%q<resque>, [">= 0"])
@@ -147,3 +147,23 @@ describe "Acceptance: Task needing to reference the original Multi-Step-Task" do
147
147
  Resque.queues.should_not include(task.queue_name)
148
148
  end
149
149
  end
150
+
151
+ describe "Acceptance: Finalization always runs" do
152
+ let(:task) do
153
+ Resque::Plugins::MultiStepTask.create("testing")
154
+ end
155
+
156
+ before do
157
+ Resque.redis.del "testing"
158
+ task.add_job MultiStepAcceptance::CounterJob, "testing counter"
159
+ task.add_job MultiStepAcceptance::CounterJob, "testing counter"
160
+ task.add_finalization_job MultiStepAcceptance::CounterJob, "testing counter"
161
+ sleep 1
162
+ task.finalizable!
163
+ sleep 1
164
+ end
165
+
166
+ it 'should run normal jobs and finalization job' do
167
+ Resque.redis.get("testing counter").to_i.should == 3
168
+ end
169
+ end
@@ -3,11 +3,22 @@ require File.expand_path("../spec_helper", File.dirname(__FILE__))
3
3
  $LOAD_PATH << File.dirname(__FILE__)
4
4
  require 'acceptance_jobs'
5
5
 
6
- $worker_pid = fork
7
- if $worker_pid.nil?
8
- # in child
9
- exec "rake resque:work 'QUEUES=*' 'NAMESPACE=resque-multi-step-task-testing' INTERVAL=1 VERBOSE=1"
10
- end
6
+ RSpec.configure do |c|
7
+ c.before(:all) do
8
+ puts '---------- Starting Resque Workers ----------'
9
+ 3.times do |index|
10
+ system "BACKGROUND=yes PIDFILE=resque#{index}.pid QUEUE=* NAMESPACE=resque-multi-step-task-testing INTERVAL=0.5 rake resque:work"
11
+ end
12
+ sleep 3
13
+ end
11
14
 
12
- # wait for worker to come up
13
- sleep 4
15
+ c.after(:all) do
16
+ sleep 1
17
+ puts '---------- Stopping Resque Workers ----------'
18
+ 3.times do |index|
19
+ pid = File.read("resque#{index}.pid").to_i
20
+ File.delete("resque#{index}.pid")
21
+ Process.kill('QUIT', pid)
22
+ end
23
+ end
24
+ 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").start}
48
48
 
49
49
  it "allows jobs to be added to task" do
50
50
  lambda {
@@ -86,7 +86,7 @@ module Resque::Plugins
86
86
  end
87
87
 
88
88
  describe MultiStepTask, "synchronous mode" do
89
- let(:task){MultiStepTask.create("some-task")}
89
+ let(:task){MultiStepTask.create("some-task").start}
90
90
 
91
91
  before do
92
92
  MultiStepTask.mode = :sync
metadata CHANGED
@@ -1,8 +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.3
5
- prerelease:
4
+ version: 2.0.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Peter Williams
@@ -10,134 +9,90 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2014-02-05 00:00:00.000000000 Z
12
+ date: 2014-09-09 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: resque-multi-step
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - ">="
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - ">="
29
26
  - !ruby/object:Gem::Version
30
27
  version: '0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rspec
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - ">="
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
- - !ruby/object:Gem::Dependency
48
- name: rspec
49
- requirement: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :development
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- - !ruby/object:Gem::Dependency
64
- name: rspec
65
- requirement: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
- type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
39
+ - - ">="
77
40
  - !ruby/object:Gem::Version
78
41
  version: '0'
79
42
  - !ruby/object:Gem::Dependency
80
43
  name: redis-namespace
81
44
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
45
  requirements:
84
- - - ! '>='
46
+ - - ">="
85
47
  - !ruby/object:Gem::Version
86
48
  version: '0'
87
49
  type: :runtime
88
50
  prerelease: false
89
51
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
52
  requirements:
92
- - - ! '>='
53
+ - - ">="
93
54
  - !ruby/object:Gem::Version
94
55
  version: '0'
95
56
  - !ruby/object:Gem::Dependency
96
57
  name: yajl-ruby
97
58
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
59
  requirements:
100
- - - ! '>='
60
+ - - ">="
101
61
  - !ruby/object:Gem::Version
102
62
  version: '0'
103
63
  type: :runtime
104
64
  prerelease: false
105
65
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
66
  requirements:
108
- - - ! '>='
67
+ - - ">="
109
68
  - !ruby/object:Gem::Version
110
69
  version: '0'
111
70
  - !ruby/object:Gem::Dependency
112
71
  name: resque
113
72
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
73
  requirements:
116
- - - ! '>='
74
+ - - ">="
117
75
  - !ruby/object:Gem::Version
118
76
  version: '0'
119
77
  type: :runtime
120
78
  prerelease: false
121
79
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
80
  requirements:
124
- - - ! '>='
81
+ - - ">="
125
82
  - !ruby/object:Gem::Version
126
83
  version: '0'
127
84
  - !ruby/object:Gem::Dependency
128
85
  name: resque-fairly
129
86
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
87
  requirements:
132
- - - ! '>='
88
+ - - ">="
133
89
  - !ruby/object:Gem::Version
134
90
  version: '0'
135
91
  type: :runtime
136
92
  prerelease: false
137
93
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
94
  requirements:
140
- - - ! '>='
95
+ - - ">="
141
96
  - !ruby/object:Gem::Version
142
97
  version: '0'
143
98
  description: Provides multi-step tasks with finalization and progress tracking
@@ -148,7 +103,7 @@ extra_rdoc_files:
148
103
  - LICENSE
149
104
  - README.md
150
105
  files:
151
- - .document
106
+ - ".document"
152
107
  - Gemfile
153
108
  - Gemfile.lock
154
109
  - History.txt
@@ -174,25 +129,24 @@ files:
174
129
  - spec/spec_helper.rb
175
130
  homepage: http://github.com/pezra/resque-multi-step
176
131
  licenses: []
132
+ metadata: {}
177
133
  post_install_message:
178
134
  rdoc_options: []
179
135
  require_paths:
180
136
  - lib
181
137
  required_ruby_version: !ruby/object:Gem::Requirement
182
- none: false
183
138
  requirements:
184
- - - ! '>='
139
+ - - ">="
185
140
  - !ruby/object:Gem::Version
186
141
  version: '0'
187
142
  required_rubygems_version: !ruby/object:Gem::Requirement
188
- none: false
189
143
  requirements:
190
- - - ! '>='
144
+ - - ">="
191
145
  - !ruby/object:Gem::Version
192
146
  version: '0'
193
147
  requirements: []
194
148
  rubyforge_project:
195
- rubygems_version: 1.8.23
149
+ rubygems_version: 2.2.2
196
150
  signing_key:
197
151
  specification_version: 3
198
152
  summary: Provides multi-step tasks with finalization and progress tracking