resque-status 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +35 -9
- data/README.rdoc +10 -1
- data/Rakefile +1 -11
- data/lib/resque/plugins/status.rb +19 -6
- data/lib/resque/plugins/status/hash.rb +17 -14
- data/lib/resque/server/views/status.erb +1 -1
- data/resque-status.gemspec +6 -5
- data/test/test_helper.rb +1 -1
- data/test/test_resque_plugins_status.rb +4 -11
- data/test/test_resque_plugins_status_hash.rb +21 -0
- metadata +12 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 323c2f3b3316e4beac0112382865580010032cd9
|
4
|
+
data.tar.gz: bed8bbe784ec2165cd79b9e92b035456e45890ce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0a2dd540a7e6be2758f84b0150c3a165f5bc8b439131327e3174a87a697a409b617c73cb572855a2347cca4f4723d8fc3d2e666a711c7fa2e9d84a4444bf269f
|
7
|
+
data.tar.gz: 0b991464b6f793b216b518586b6b23a20ffc19ce2c89265f9af571e88bb085ae1e12eb6a5d2a8a6e6bb2192273f0849286973aaddc6ba1a8d73fc557347a8c47
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,20 +1,46 @@
|
|
1
1
|
GEM
|
2
|
-
remote:
|
2
|
+
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
addressable (2.3.5)
|
5
|
+
builder (3.2.2)
|
6
|
+
faraday (0.7.6)
|
7
|
+
addressable (~> 2.2)
|
8
|
+
multipart-post (~> 1.1)
|
9
|
+
rack (~> 1.1)
|
10
|
+
git (1.2.6)
|
11
|
+
github_api (0.4.10)
|
12
|
+
faraday (~> 0.7.6)
|
13
|
+
hashie (~> 1.2.0)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
oauth2 (~> 0.5.2)
|
16
|
+
hashie (1.2.0)
|
17
|
+
highline (1.6.20)
|
18
|
+
jeweler (2.0.0)
|
19
|
+
builder
|
20
|
+
bundler (>= 1.0)
|
7
21
|
git (>= 1.2.5)
|
22
|
+
github_api
|
23
|
+
highline (>= 1.6.15)
|
24
|
+
nokogiri (>= 1.5.10)
|
8
25
|
rake
|
9
26
|
rdoc
|
10
|
-
json (1.
|
11
|
-
|
27
|
+
json (1.8.1)
|
28
|
+
metaclass (0.0.2)
|
29
|
+
mini_portile (0.5.2)
|
30
|
+
mocha (0.14.0)
|
31
|
+
metaclass (~> 0.0.1)
|
12
32
|
multi_json (1.3.6)
|
33
|
+
multipart-post (1.2.0)
|
34
|
+
nokogiri (1.6.1)
|
35
|
+
mini_portile (~> 0.5.0)
|
36
|
+
oauth2 (0.5.2)
|
37
|
+
faraday (~> 0.7)
|
38
|
+
multi_json (~> 1.0)
|
13
39
|
rack (1.4.1)
|
14
40
|
rack-protection (1.2.0)
|
15
41
|
rack
|
16
|
-
rake (
|
17
|
-
rdoc (
|
42
|
+
rake (10.1.1)
|
43
|
+
rdoc (4.1.1)
|
18
44
|
json (~> 1.4)
|
19
45
|
redis (3.0.2)
|
20
46
|
redis-namespace (1.2.1)
|
@@ -38,6 +64,6 @@ PLATFORMS
|
|
38
64
|
|
39
65
|
DEPENDENCIES
|
40
66
|
jeweler
|
41
|
-
mocha (~> 0.9
|
67
|
+
mocha (~> 0.9)
|
42
68
|
resque (~> 1.19)
|
43
69
|
shoulda (~> 2.10.2)
|
data/README.rdoc
CHANGED
@@ -136,9 +136,18 @@ error and set the status to killed.
|
|
136
136
|
|
137
137
|
Since Redis is RAM based, we probably don't want to keep these statuses around forever
|
138
138
|
(at least until @antirez releases the VM feature). By setting expire_in, all statuses
|
139
|
-
and
|
139
|
+
and their related keys will expire in expire_in seconds from the last time theyre updated:
|
140
140
|
|
141
141
|
Resque::Plugins::Status::Hash.expire_in = (60 * 60) # 1 hour
|
142
|
+
=== Testing
|
143
|
+
|
144
|
+
Recent versions of Resque introduced `Resque.inline` which changes the behavior to
|
145
|
+
instead of enqueueing and performing jobs to just executing them inline. In Resque
|
146
|
+
itself this removes the dependency on a Redis, however, `Resque::Status` uses Redis
|
147
|
+
to store information about jobs, so though `inline` "works", you will still need
|
148
|
+
to use or mock a redis connection. You should be able to use a library like
|
149
|
+
https://github.com/causes/mock_redis alongside `inline` if you really want to
|
150
|
+
avoid Redis connections in your test.
|
142
151
|
|
143
152
|
=== resque-web
|
144
153
|
|
data/Rakefile
CHANGED
@@ -18,7 +18,7 @@ begin
|
|
18
18
|
gem.authors = ["Aaron Quint"]
|
19
19
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
20
|
end
|
21
|
-
Jeweler::
|
21
|
+
Jeweler::RubygemsDotOrgTasks.new
|
22
22
|
rescue LoadError
|
23
23
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
24
24
|
end
|
@@ -46,13 +46,3 @@ end
|
|
46
46
|
task :test
|
47
47
|
|
48
48
|
task :default => :test
|
49
|
-
|
50
|
-
require 'rake/rdoctask'
|
51
|
-
Rake::RDocTask.new do |rdoc|
|
52
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
-
|
54
|
-
rdoc.rdoc_dir = 'rdoc'
|
55
|
-
rdoc.title = "resque-status #{version}"
|
56
|
-
rdoc.rdoc_files.include('README*')
|
57
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
-
end
|
@@ -28,7 +28,20 @@ module Resque
|
|
28
28
|
# This job would iterate num times updating the status as it goes. At the end
|
29
29
|
# we update the status telling anyone listening to this job that its complete.
|
30
30
|
module Status
|
31
|
-
VERSION = '0.4.
|
31
|
+
VERSION = '0.4.2'
|
32
|
+
|
33
|
+
STATUS_QUEUED = 'queued'
|
34
|
+
STATUS_WORKING = 'working'
|
35
|
+
STATUS_COMPLETED = 'completed'
|
36
|
+
STATUS_FAILED = 'failed'
|
37
|
+
STATUS_KILLED = 'killed'
|
38
|
+
STATUSES = [
|
39
|
+
STATUS_QUEUED,
|
40
|
+
STATUS_WORKING,
|
41
|
+
STATUS_COMPLETED,
|
42
|
+
STATUS_FAILED,
|
43
|
+
STATUS_KILLED
|
44
|
+
].freeze
|
32
45
|
|
33
46
|
autoload :Hash, 'resque/plugins/status/hash'
|
34
47
|
|
@@ -144,7 +157,7 @@ module Resque
|
|
144
157
|
# If an error occurs within the job's work, it will set the status as failed and
|
145
158
|
# re-raise the error.
|
146
159
|
def safe_perform!
|
147
|
-
set_status({'status' =>
|
160
|
+
set_status({'status' => STATUS_WORKING})
|
148
161
|
perform
|
149
162
|
if status && status.failed?
|
150
163
|
on_failure(status.message) if respond_to?(:on_failure)
|
@@ -206,18 +219,18 @@ module Resque
|
|
206
219
|
# <tt>Resque::Plugins::Status::Hash.kill()</tt>
|
207
220
|
def tick(*messages)
|
208
221
|
kill! if should_kill?
|
209
|
-
set_status({'status' =>
|
222
|
+
set_status({'status' => STATUS_WORKING}, *messages)
|
210
223
|
end
|
211
224
|
|
212
225
|
# set the status to 'failed' passing along any additional messages
|
213
226
|
def failed(*messages)
|
214
|
-
set_status({'status' =>
|
227
|
+
set_status({'status' => STATUS_FAILED}, *messages)
|
215
228
|
end
|
216
229
|
|
217
230
|
# set the status to 'completed' passing along any addional messages
|
218
231
|
def completed(*messages)
|
219
232
|
set_status({
|
220
|
-
'status' =>
|
233
|
+
'status' => STATUS_COMPLETED,
|
221
234
|
'message' => "Completed at #{Time.now}"
|
222
235
|
}, *messages)
|
223
236
|
end
|
@@ -225,7 +238,7 @@ module Resque
|
|
225
238
|
# kill the current job, setting the status to 'killed' and raising <tt>Killed</tt>
|
226
239
|
def kill!
|
227
240
|
set_status({
|
228
|
-
'status' =>
|
241
|
+
'status' => STATUS_KILLED,
|
229
242
|
'message' => "Killed at #{Time.now}"
|
230
243
|
})
|
231
244
|
raise Killed
|
@@ -9,8 +9,6 @@ module Resque
|
|
9
9
|
# creating/updating/retrieving status objects from Redis
|
10
10
|
class Hash < ::Hash
|
11
11
|
|
12
|
-
extend Resque::Helpers
|
13
|
-
|
14
12
|
# Create a status, generating a new UUID, passing the message to the status
|
15
13
|
# Returns the UUID of the new status.
|
16
14
|
def self.create(uuid, *messages)
|
@@ -87,9 +85,8 @@ module Resque
|
|
87
85
|
# @example retuning the last 20 statuses
|
88
86
|
# Resque::Plugins::Status::Hash.statuses(0, 20)
|
89
87
|
def self.statuses(range_start = nil, range_end = nil)
|
90
|
-
status_ids(range_start, range_end)
|
91
|
-
|
92
|
-
end.compact
|
88
|
+
ids = status_ids(range_start, range_end)
|
89
|
+
mget(ids).compact
|
93
90
|
end
|
94
91
|
|
95
92
|
# Return the <tt>num</tt> most recent status/job UUIDs in reverse chronological order.
|
@@ -190,7 +187,12 @@ module Resque
|
|
190
187
|
EOT
|
191
188
|
end
|
192
189
|
|
193
|
-
|
190
|
+
# Proxy deprecated methods directly back to Resque itself.
|
191
|
+
class << self
|
192
|
+
[:redis, :encode, :decode].each do |method|
|
193
|
+
define_method(method) { |*args| Resque.send(method, *args) }
|
194
|
+
end
|
195
|
+
end
|
194
196
|
|
195
197
|
hash_accessor :uuid
|
196
198
|
hash_accessor :name
|
@@ -210,7 +212,7 @@ module Resque
|
|
210
212
|
super nil
|
211
213
|
base_status = {
|
212
214
|
'time' => Time.now.to_i,
|
213
|
-
'status' =>
|
215
|
+
'status' => Resque::Plugins::Status::STATUS_QUEUED
|
214
216
|
}
|
215
217
|
base_status['uuid'] = args.shift if args.length > 1
|
216
218
|
status_hash = args.inject(base_status) do |final, m|
|
@@ -223,9 +225,10 @@ module Resque
|
|
223
225
|
# calculate the % completion of the job based on <tt>status</tt>, <tt>num</tt>
|
224
226
|
# and <tt>total</tt>
|
225
227
|
def pct_complete
|
226
|
-
|
227
|
-
|
228
|
-
|
228
|
+
if completed?
|
229
|
+
100
|
230
|
+
elsif queued?
|
231
|
+
0
|
229
232
|
else
|
230
233
|
t = (total == 0 || total.nil?) ? 1 : total
|
231
234
|
(((num || 0).to_f / t.to_f) * 100).to_i
|
@@ -238,16 +241,16 @@ module Resque
|
|
238
241
|
time? ? Time.at(self['time']) : nil
|
239
242
|
end
|
240
243
|
|
241
|
-
STATUSES.each do |status|
|
244
|
+
Resque::Plugins::Status::STATUSES.each do |status|
|
242
245
|
define_method("#{status}?") do
|
243
246
|
self['status'] === status
|
244
247
|
end
|
245
248
|
end
|
246
249
|
|
247
|
-
# Can the job be killed?
|
248
|
-
#
|
250
|
+
# Can the job be killed? failed, completed, and killed jobs can't be
|
251
|
+
# killed, for obvious reasons
|
249
252
|
def killable?
|
250
|
-
!
|
253
|
+
!failed? && !completed? && !killed?
|
251
254
|
end
|
252
255
|
|
253
256
|
unless method_defined?(:to_json)
|
@@ -67,7 +67,7 @@
|
|
67
67
|
}
|
68
68
|
};
|
69
69
|
var status = $status.attr('rel');
|
70
|
-
if (status == '
|
70
|
+
if (status == '<%= Resque::Plugins::Status::STATUS_WORKING %>' || status == '<%= Resque::Plugins::Status::STATUS_QUEUED %>' || status == "") {
|
71
71
|
setTimeout(function() {
|
72
72
|
checkStatus($status)
|
73
73
|
}, 1500);
|
data/resque-status.gemspec
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: resque-status 0.4.2 ruby lib
|
5
6
|
|
6
7
|
Gem::Specification.new do |s|
|
7
8
|
s.name = "resque-status"
|
8
|
-
s.version = "0.4.
|
9
|
+
s.version = "0.4.2"
|
9
10
|
|
10
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
11
13
|
s.authors = ["Aaron Quint"]
|
12
|
-
s.date = "
|
14
|
+
s.date = "2014-01-21"
|
13
15
|
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
16
|
s.email = "aaron@quirkey.com"
|
15
17
|
s.extra_rdoc_files = [
|
@@ -41,13 +43,12 @@ Gem::Specification.new do |s|
|
|
41
43
|
"test/test_resque_plugins_status_hash.rb"
|
42
44
|
]
|
43
45
|
s.homepage = "http://github.com/quirkey/resque-status"
|
44
|
-
s.require_paths = ["lib"]
|
45
46
|
s.rubyforge_project = "quirkey"
|
46
|
-
s.rubygems_version = "
|
47
|
+
s.rubygems_version = "2.2.1"
|
47
48
|
s.summary = "resque-status is an extension to the resque queue system that provides simple trackable jobs."
|
48
49
|
|
49
50
|
if s.respond_to? :specification_version then
|
50
|
-
s.specification_version =
|
51
|
+
s.specification_version = 4
|
51
52
|
|
52
53
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
54
|
s.add_runtime_dependency(%q<resque>, ["~> 1.19"])
|
data/test/test_helper.rb
CHANGED
@@ -193,7 +193,6 @@ class TestResquePluginsStatus < Test::Unit::TestCase
|
|
193
193
|
end
|
194
194
|
|
195
195
|
should "set the status to killed" do
|
196
|
-
assert_equal 'killed', @status.status
|
197
196
|
assert @status.killed?
|
198
197
|
assert !@status.completed?
|
199
198
|
end
|
@@ -227,11 +226,8 @@ class TestResquePluginsStatus < Test::Unit::TestCase
|
|
227
226
|
end
|
228
227
|
|
229
228
|
should "set the status to killed" do
|
230
|
-
assert_equal 'killed', @status1.status
|
231
229
|
assert @status1.killed?
|
232
230
|
assert !@status1.completed?
|
233
|
-
|
234
|
-
assert_equal 'killed', @status2.status
|
235
231
|
assert @status2.killed?
|
236
232
|
assert !@status2.completed?
|
237
233
|
end
|
@@ -268,11 +264,8 @@ class TestResquePluginsStatus < Test::Unit::TestCase
|
|
268
264
|
end
|
269
265
|
|
270
266
|
should "set the status to killed" do
|
271
|
-
assert_equal 'completed', @status1.status
|
272
267
|
assert !@status1.killed?
|
273
268
|
assert @status1.completed?
|
274
|
-
|
275
|
-
assert_equal 'killed', @status2.status
|
276
269
|
assert @status2.killed?
|
277
270
|
assert !@status2.completed?
|
278
271
|
end
|
@@ -304,7 +297,7 @@ class TestResquePluginsStatus < Test::Unit::TestCase
|
|
304
297
|
end
|
305
298
|
|
306
299
|
should "set status" do
|
307
|
-
|
300
|
+
assert @job.status.working?
|
308
301
|
end
|
309
302
|
|
310
303
|
should "save message" do
|
@@ -318,7 +311,7 @@ class TestResquePluginsStatus < Test::Unit::TestCase
|
|
318
311
|
end
|
319
312
|
|
320
313
|
should "set status" do
|
321
|
-
|
314
|
+
assert @job.status.failed?
|
322
315
|
end
|
323
316
|
|
324
317
|
should "set message" do
|
@@ -332,7 +325,7 @@ class TestResquePluginsStatus < Test::Unit::TestCase
|
|
332
325
|
end
|
333
326
|
|
334
327
|
should "set status" do
|
335
|
-
|
328
|
+
assert @job.status.completed?
|
336
329
|
end
|
337
330
|
|
338
331
|
should "set message" do
|
@@ -350,7 +343,7 @@ class TestResquePluginsStatus < Test::Unit::TestCase
|
|
350
343
|
end
|
351
344
|
|
352
345
|
should "set status as failed" do
|
353
|
-
|
346
|
+
assert @job.status.failed?
|
354
347
|
end
|
355
348
|
end
|
356
349
|
|
@@ -190,6 +190,27 @@ class TestResquePluginsStatusHash < Test::Unit::TestCase
|
|
190
190
|
end
|
191
191
|
|
192
192
|
end
|
193
|
+
|
194
|
+
Resque::Plugins::Status::STATUSES.each do |status_code|
|
195
|
+
context ".#{status_code}?" do
|
196
|
+
|
197
|
+
setup do
|
198
|
+
uuid = Resque::Plugins::Status::Hash.create(Resque::Plugins::Status::Hash.generate_uuid, {'status' => status_code})
|
199
|
+
@status = Resque::Plugins::Status::Hash.get(uuid)
|
200
|
+
end
|
201
|
+
|
202
|
+
should "return true for the current status" do
|
203
|
+
assert @status.send("#{status_code}?"), status_code
|
204
|
+
end
|
205
|
+
|
206
|
+
should "return false for other statuses" do
|
207
|
+
(Resque::Plugins::Status::STATUSES - [status_code]).each do |other_status_code|
|
208
|
+
assert !@status.send("#{other_status_code}?"), other_status_code
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
end
|
193
214
|
end
|
194
215
|
|
195
216
|
end
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-status
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Aaron Quint
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-01-21 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: resque
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.19'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.19'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: jeweler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: resque-status is an extension to the resque queue system that provides
|
@@ -54,7 +49,7 @@ extra_rdoc_files:
|
|
54
49
|
- LICENSE
|
55
50
|
- README.rdoc
|
56
51
|
files:
|
57
|
-
- .document
|
52
|
+
- ".document"
|
58
53
|
- Gemfile
|
59
54
|
- Gemfile.lock
|
60
55
|
- LICENSE
|
@@ -78,30 +73,26 @@ files:
|
|
78
73
|
- test/test_resque_plugins_status_hash.rb
|
79
74
|
homepage: http://github.com/quirkey/resque-status
|
80
75
|
licenses: []
|
76
|
+
metadata: {}
|
81
77
|
post_install_message:
|
82
78
|
rdoc_options: []
|
83
79
|
require_paths:
|
84
80
|
- lib
|
85
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
82
|
requirements:
|
88
|
-
- -
|
83
|
+
- - ">="
|
89
84
|
- !ruby/object:Gem::Version
|
90
85
|
version: '0'
|
91
|
-
segments:
|
92
|
-
- 0
|
93
|
-
hash: -3693274209748855583
|
94
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
-
none: false
|
96
87
|
requirements:
|
97
|
-
- -
|
88
|
+
- - ">="
|
98
89
|
- !ruby/object:Gem::Version
|
99
90
|
version: '0'
|
100
91
|
requirements: []
|
101
92
|
rubyforge_project: quirkey
|
102
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.2.1
|
103
94
|
signing_key:
|
104
|
-
specification_version:
|
95
|
+
specification_version: 4
|
105
96
|
summary: resque-status is an extension to the resque queue system that provides simple
|
106
97
|
trackable jobs.
|
107
98
|
test_files: []
|