resque-status 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,8 +1,14 @@
1
1
  source :rubygems
2
2
 
3
3
  gem 'redisk', '>= 0.2.1'
4
- gem 'resque', '>= 1.3.1'
5
- gem 'uuid', '>= 2.0.2'
6
- gem 'mocha', '>= 0.9.8'
7
- gem 'shoulda', '>= 2.10.2'
8
- gem 'jeweler'
4
+ gem 'resque', '~>1.19'
5
+ gem 'uuid', '~>2.0.2'
6
+
7
+ group :test do
8
+ gem 'mocha', '~>0.9.8'
9
+ gem 'shoulda', '~>2.10.2'
10
+ end
11
+
12
+ group :development do
13
+ gem 'jeweler'
14
+ end
data/Gemfile.lock CHANGED
@@ -6,35 +6,33 @@ GEM
6
6
  bundler (~> 1.0)
7
7
  git (>= 1.2.5)
8
8
  rake
9
- json (1.4.6)
10
9
  macaddr (1.5.0)
11
10
  systemu (>= 2.4.0)
12
- metaclass (0.0.1)
13
- mocha (0.10.3)
14
- metaclass (~> 0.0.1)
11
+ mocha (0.9.12)
12
+ multi_json (1.0.4)
15
13
  rack (1.4.0)
16
14
  rack-protection (1.2.0)
17
15
  rack
18
16
  rake (0.9.2.2)
19
17
  redis (2.2.2)
20
- redis-namespace (1.1.0)
18
+ redis-namespace (1.0.3)
21
19
  redis (< 3.0.0)
22
20
  redisk (0.2.2)
23
21
  redis (>= 0.1.1)
24
22
  redis-namespace (>= 0.1.0)
25
- resque (1.15.0)
26
- json (~> 1.4.6)
27
- redis-namespace (>= 0.10.0)
23
+ resque (1.19.0.1)
24
+ multi_json (~> 1.0)
25
+ redis-namespace (~> 1.0.2)
28
26
  sinatra (>= 0.9.2)
29
27
  vegas (~> 0.1.2)
30
- shoulda (2.11.3)
28
+ shoulda (2.10.3)
31
29
  sinatra (1.3.2)
32
30
  rack (~> 1.3, >= 1.3.6)
33
31
  rack-protection (~> 1.2)
34
32
  tilt (~> 1.3, >= 1.3.3)
35
33
  systemu (2.4.2)
36
34
  tilt (1.3.3)
37
- uuid (2.3.4)
35
+ uuid (2.0.2)
38
36
  macaddr (~> 1.0)
39
37
  vegas (0.1.8)
40
38
  rack (>= 1.0.0)
@@ -44,8 +42,8 @@ PLATFORMS
44
42
 
45
43
  DEPENDENCIES
46
44
  jeweler
47
- mocha (>= 0.9.8)
45
+ mocha (~> 0.9.8)
48
46
  redisk (>= 0.2.1)
49
- resque (>= 1.3.1)
50
- shoulda (>= 2.10.2)
51
- uuid (>= 2.0.2)
47
+ resque (~> 1.19)
48
+ shoulda (~> 2.10.2)
49
+ uuid (~> 2.0.2)
data/Rakefile CHANGED
@@ -16,11 +16,6 @@ begin
16
16
  gem.homepage = "http://github.com/quirkey/resque-status"
17
17
  gem.rubyforge_project = "quirkey"
18
18
  gem.authors = ["Aaron Quint"]
19
- gem.add_dependency "uuid", ">=2.0.2"
20
- gem.add_dependency "resque", ">=1.3.1"
21
- gem.add_dependency "redisk", ">=0.2.1"
22
- gem.add_development_dependency "shoulda", ">=2.10.2"
23
- gem.add_development_dependency "mocha", ">=0.9.8"
24
19
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
25
20
  end
26
21
  Jeweler::GemcutterTasks.new
@@ -30,6 +30,7 @@ module Resque
30
30
  # This job would iterate num times updating the status as it goes. At the end
31
31
  # we update the status telling anyone listening to this job that its complete.
32
32
  module Status
33
+ VERSION = '0.3.1'
33
34
 
34
35
  # The error class raised when a job is killed
35
36
  class Killed < RuntimeError; end
@@ -119,7 +120,12 @@ module Resque
119
120
  def safe_perform!
120
121
  set_status({'status' => 'working'})
121
122
  perform
122
- completed unless status && status.completed?
123
+ if status.failed?
124
+ on_failure(status.message) if respond_to?(:on_failure)
125
+ return
126
+ elsif status && !status.completed?
127
+ completed
128
+ end
123
129
  on_success if respond_to?(:on_success)
124
130
  rescue Killed
125
131
  logger.info "Job #{self} Killed at #{Time.now}"
@@ -1,7 +1,6 @@
1
1
  module Resque
2
2
  module Plugins
3
3
  module Status
4
- VERSION = '0.3.0'
5
4
 
6
5
  # Resque::Plugins::Status::Hash is a Hash object that has helper methods for dealing with
7
6
  # the common status attributes. It also has a number of class methods for
@@ -103,6 +102,20 @@ module Resque
103
102
  redis.smembers(kill_key)
104
103
  end
105
104
 
105
+ # Kills <tt>num</tt> jobs within range starting with the most recent first.
106
+ # By default kills all jobs.
107
+ # Note that the same conditions apply as <tt>kill</tt>, i.e. only jobs that check
108
+ # on each iteration by calling <tt>tick</tt> or <tt>at</tt> are eligible to killed.
109
+ # @param [Numeric] range_start The optional starting range
110
+ # @param [Numeric] range_end The optional ending range
111
+ # @example killing the last 20 submitted jobs
112
+ # Resque::Plugins::Status::Hash.killall(0, 20)
113
+ def self.killall(range_start = nil, range_end = nil)
114
+ status_ids(range_start, range_end).collect do |id|
115
+ kill(id)
116
+ end
117
+ end
118
+
106
119
  # Check whether a job with UUID is on the kill list
107
120
  def self.should_kill?(uuid)
108
121
  redis.sismember(kill_key, uuid)
@@ -1,3 +1,4 @@
1
+ require 'resque/server'
1
2
  require 'resque-status'
2
3
 
3
4
  module Resque
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "resque-status"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Quint"]
12
- s.date = "2012-01-22"
12
+ s.date = "2012-01-23"
13
13
  s.description = "resque-status is an extension to the resque queue system that provides simple trackable jobs. It provides a Resque::Plugins::Status::Hash class which can set/get the statuses of jobs and a Resque::Plugins::Status class that when included provides easily trackable/killable jobs."
14
14
  s.email = "aaron@quirkey.com"
15
15
  s.extra_rdoc_files = [
@@ -51,41 +51,20 @@ Gem::Specification.new do |s|
51
51
 
52
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
53
  s.add_runtime_dependency(%q<redisk>, [">= 0.2.1"])
54
- s.add_runtime_dependency(%q<resque>, [">= 1.3.1"])
55
- s.add_runtime_dependency(%q<uuid>, [">= 2.0.2"])
56
- s.add_runtime_dependency(%q<mocha>, [">= 0.9.8"])
57
- s.add_runtime_dependency(%q<shoulda>, [">= 2.10.2"])
58
- s.add_runtime_dependency(%q<jeweler>, [">= 0"])
59
- s.add_runtime_dependency(%q<uuid>, [">= 2.0.2"])
60
- s.add_runtime_dependency(%q<resque>, [">= 1.3.1"])
61
- s.add_runtime_dependency(%q<redisk>, [">= 0.2.1"])
62
- s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
63
- s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
54
+ s.add_runtime_dependency(%q<resque>, ["~> 1.19"])
55
+ s.add_runtime_dependency(%q<uuid>, ["~> 2.0.2"])
56
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
64
57
  else
65
58
  s.add_dependency(%q<redisk>, [">= 0.2.1"])
66
- s.add_dependency(%q<resque>, [">= 1.3.1"])
67
- s.add_dependency(%q<uuid>, [">= 2.0.2"])
68
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
69
- s.add_dependency(%q<shoulda>, [">= 2.10.2"])
59
+ s.add_dependency(%q<resque>, ["~> 1.19"])
60
+ s.add_dependency(%q<uuid>, ["~> 2.0.2"])
70
61
  s.add_dependency(%q<jeweler>, [">= 0"])
71
- s.add_dependency(%q<uuid>, [">= 2.0.2"])
72
- s.add_dependency(%q<resque>, [">= 1.3.1"])
73
- s.add_dependency(%q<redisk>, [">= 0.2.1"])
74
- s.add_dependency(%q<shoulda>, [">= 2.10.2"])
75
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
76
62
  end
77
63
  else
78
64
  s.add_dependency(%q<redisk>, [">= 0.2.1"])
79
- s.add_dependency(%q<resque>, [">= 1.3.1"])
80
- s.add_dependency(%q<uuid>, [">= 2.0.2"])
81
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
82
- s.add_dependency(%q<shoulda>, [">= 2.10.2"])
65
+ s.add_dependency(%q<resque>, ["~> 1.19"])
66
+ s.add_dependency(%q<uuid>, ["~> 2.0.2"])
83
67
  s.add_dependency(%q<jeweler>, [">= 0"])
84
- s.add_dependency(%q<uuid>, [">= 2.0.2"])
85
- s.add_dependency(%q<resque>, [">= 1.3.1"])
86
- s.add_dependency(%q<redisk>, [">= 0.2.1"])
87
- s.add_dependency(%q<shoulda>, [">= 2.10.2"])
88
- s.add_dependency(%q<mocha>, [">= 0.9.8"])
89
68
  end
90
69
  end
91
70
 
data/test/test_helper.rb CHANGED
@@ -89,3 +89,11 @@ end
89
89
  class BasicJob
90
90
  include Resque::Plugins::Status
91
91
  end
92
+
93
+ class FailureJob
94
+ include Resque::Plugins::Status
95
+
96
+ def perform
97
+ failed("I'm such a failure")
98
+ end
99
+ end
@@ -93,6 +93,32 @@ class TestResquePluginsStatus < Test::Unit::TestCase
93
93
  before_should "call perform on the inherited class" do
94
94
  WorkingJob.any_instance.expects(:perform).once
95
95
  end
96
+ end
97
+
98
+ context "manually failing a job" do
99
+ setup do
100
+ @uuid = FailureJob.create(:num => 100)
101
+ @payload = Resque.pop(:statused)
102
+ @performed = FailureJob.perform(*@payload['args'])
103
+ end
104
+
105
+ should "load load a new instance of the klass" do
106
+ assert @performed.is_a?(FailureJob)
107
+ end
108
+
109
+ should "set the uuid" do
110
+ assert_equal @uuid, @performed.uuid
111
+ end
112
+
113
+ should "set the status" do
114
+ assert @performed.status.is_a?(Resque::Plugins::Status::Hash)
115
+ assert_equal 'FailureJob({"num"=>100})', @performed.status.name
116
+ end
117
+
118
+ should "be failed" do
119
+ assert_match(/failure/, @performed.status.message)
120
+ assert @performed.status.failed?
121
+ end
96
122
 
97
123
  end
98
124
 
@@ -126,10 +152,10 @@ class TestResquePluginsStatus < Test::Unit::TestCase
126
152
  @uuid1 = KillableJob.create(:num => 100)
127
153
  @uuid2 = KillableJob.create(:num => 100)
128
154
 
129
- Resque::Status.killall
155
+ Resque::Plugins::Status::Hash.killall
130
156
 
131
- assert_contains Resque::Status.kill_ids, @uuid1
132
- assert_contains Resque::Status.kill_ids, @uuid2
157
+ assert_contains Resque::Plugins::Status::Hash.kill_ids, @uuid1
158
+ assert_contains Resque::Plugins::Status::Hash.kill_ids, @uuid2
133
159
 
134
160
  @payload1 = Resque.pop(:statused)
135
161
  @payload2 = Resque.pop(:statused)
@@ -137,8 +163,8 @@ class TestResquePluginsStatus < Test::Unit::TestCase
137
163
  @performed = KillableJob.perform(*@payload1['args'])
138
164
  @performed = KillableJob.perform(*@payload2['args'])
139
165
 
140
- @status1 = Resque::Status.get(@uuid1)
141
- @status2 = Resque::Status.get(@uuid2)
166
+ @status1 = Resque::Plugins::Status::Hash.get(@uuid1)
167
+ @status2 = Resque::Plugins::Status::Hash.get(@uuid2)
142
168
  end
143
169
 
144
170
  should "set the status to killed" do
@@ -157,8 +183,8 @@ class TestResquePluginsStatus < Test::Unit::TestCase
157
183
  end
158
184
 
159
185
  should "not persist the kill key" do
160
- assert_does_not_contain Resque::Status.kill_ids, @uuid1
161
- assert_does_not_contain Resque::Status.kill_ids, @uuid2
186
+ assert_does_not_contain Resque::Plugins::Status::Hash.kill_ids, @uuid1
187
+ assert_does_not_contain Resque::Plugins::Status::Hash.kill_ids, @uuid2
162
188
  end
163
189
 
164
190
  end
@@ -168,10 +194,10 @@ class TestResquePluginsStatus < Test::Unit::TestCase
168
194
  @uuid1 = KillableJob.create(:num => 100)
169
195
  @uuid2 = KillableJob.create(:num => 100)
170
196
 
171
- Resque::Status.killall(0,0) # only @uuid2 should be killed
197
+ Resque::Plugins::Status::Hash.killall(0,0) # only @uuid2 should be killed
172
198
 
173
- assert_does_not_contain Resque::Status.kill_ids, @uuid1
174
- assert_contains Resque::Status.kill_ids, @uuid2
199
+ assert_does_not_contain Resque::Plugins::Status::Hash.kill_ids, @uuid1
200
+ assert_contains Resque::Plugins::Status::Hash.kill_ids, @uuid2
175
201
 
176
202
  @payload1 = Resque.pop(:statused)
177
203
  @payload2 = Resque.pop(:statused)
@@ -179,8 +205,8 @@ class TestResquePluginsStatus < Test::Unit::TestCase
179
205
  @performed = KillableJob.perform(*@payload1['args'])
180
206
  @performed = KillableJob.perform(*@payload2['args'])
181
207
 
182
- @status1 = Resque::Status.get(@uuid1)
183
- @status2 = Resque::Status.get(@uuid2)
208
+ @status1 = Resque::Plugins::Status::Hash.get(@uuid1)
209
+ @status2 = Resque::Plugins::Status::Hash.get(@uuid2)
184
210
  end
185
211
 
186
212
  should "set the status to killed" do
@@ -199,8 +225,8 @@ class TestResquePluginsStatus < Test::Unit::TestCase
199
225
  end
200
226
 
201
227
  should "not persist the kill key" do
202
- assert_does_not_contain Resque::Status.kill_ids, @uuid1
203
- assert_does_not_contain Resque::Status.kill_ids, @uuid2
228
+ assert_does_not_contain Resque::Plugins::Status::Hash.kill_ids, @uuid1
229
+ assert_does_not_contain Resque::Plugins::Status::Hash.kill_ids, @uuid2
204
230
  end
205
231
 
206
232
  end
@@ -268,7 +294,6 @@ class TestResquePluginsStatus < Test::Unit::TestCase
268
294
  should "set status as failed" do
269
295
  assert_equal 'failed', @job.status.status
270
296
  end
271
-
272
297
  end
273
298
 
274
299
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-22 00:00:00.000000000Z
12
+ date: 2012-01-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redisk
16
- requirement: &70167507502960 !ruby/object:Gem::Requirement
16
+ requirement: &70111193431380 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,117 +21,40 @@ dependencies:
21
21
  version: 0.2.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70167507502960
24
+ version_requirements: *70111193431380
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: resque
27
- requirement: &70167507502380 !ruby/object:Gem::Requirement
27
+ requirement: &70111193430860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
- - - ! '>='
30
+ - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 1.3.1
32
+ version: '1.19'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70167507502380
35
+ version_requirements: *70111193430860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: uuid
38
- requirement: &70167507501840 !ruby/object:Gem::Requirement
38
+ requirement: &70111193430060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ! '>='
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
43
  version: 2.0.2
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70167507501840
47
- - !ruby/object:Gem::Dependency
48
- name: mocha
49
- requirement: &70167507501300 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: 0.9.8
55
- type: :runtime
56
- prerelease: false
57
- version_requirements: *70167507501300
58
- - !ruby/object:Gem::Dependency
59
- name: shoulda
60
- requirement: &70167507500760 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: 2.10.2
66
- type: :runtime
67
- prerelease: false
68
- version_requirements: *70167507500760
46
+ version_requirements: *70111193430060
69
47
  - !ruby/object:Gem::Dependency
70
48
  name: jeweler
71
- requirement: &70167507500200 !ruby/object:Gem::Requirement
49
+ requirement: &70111193429380 !ruby/object:Gem::Requirement
72
50
  none: false
73
51
  requirements:
74
52
  - - ! '>='
75
53
  - !ruby/object:Gem::Version
76
54
  version: '0'
77
- type: :runtime
78
- prerelease: false
79
- version_requirements: *70167507500200
80
- - !ruby/object:Gem::Dependency
81
- name: uuid
82
- requirement: &70167507499640 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: 2.0.2
88
- type: :runtime
89
- prerelease: false
90
- version_requirements: *70167507499640
91
- - !ruby/object:Gem::Dependency
92
- name: resque
93
- requirement: &70167507499060 !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: 1.3.1
99
- type: :runtime
100
- prerelease: false
101
- version_requirements: *70167507499060
102
- - !ruby/object:Gem::Dependency
103
- name: redisk
104
- requirement: &70167507496920 !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: 0.2.1
110
- type: :runtime
111
- prerelease: false
112
- version_requirements: *70167507496920
113
- - !ruby/object:Gem::Dependency
114
- name: shoulda
115
- requirement: &70167507496200 !ruby/object:Gem::Requirement
116
- none: false
117
- requirements:
118
- - - ! '>='
119
- - !ruby/object:Gem::Version
120
- version: 2.10.2
121
- type: :development
122
- prerelease: false
123
- version_requirements: *70167507496200
124
- - !ruby/object:Gem::Dependency
125
- name: mocha
126
- requirement: &70167507495300 !ruby/object:Gem::Requirement
127
- none: false
128
- requirements:
129
- - - ! '>='
130
- - !ruby/object:Gem::Version
131
- version: 0.9.8
132
55
  type: :development
133
56
  prerelease: false
134
- version_requirements: *70167507495300
57
+ version_requirements: *70111193429380
135
58
  description: resque-status is an extension to the resque queue system that provides
136
59
  simple trackable jobs. It provides a Resque::Plugins::Status::Hash class which can
137
60
  set/get the statuses of jobs and a Resque::Plugins::Status class that when included