resque-progress 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/resque/plugins/progress.rb +9 -4
- data/lib/resque/plugins/progress/version.rb +1 -1
- data/test/progress_test.rb +50 -0
- metadata +4 -4
@@ -8,10 +8,15 @@ module Resque
|
|
8
8
|
Resque::Plugins::Meta::Metadata.send(:include, Resque::Plugins::Progress::Metadata)
|
9
9
|
end
|
10
10
|
|
11
|
-
def at(num, total, message)
|
12
|
-
meta = get_meta(meta_id)
|
13
|
-
|
14
|
-
|
11
|
+
def at(num, total, message = nil)
|
12
|
+
if meta = get_meta(@meta_id)
|
13
|
+
meta.progress = [num, total, message]
|
14
|
+
meta.save
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def before_perform_progress(meta_id, *args)
|
19
|
+
@meta_id = meta_id
|
15
20
|
end
|
16
21
|
|
17
22
|
module Metadata
|
data/test/progress_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'digest/sha1'
|
1
2
|
require 'resque'
|
2
3
|
require 'resque/plugins/progress'
|
3
4
|
require 'resque/plugins/progress/version'
|
@@ -10,6 +11,31 @@ class ProgressJob
|
|
10
11
|
10
|
11
12
|
end
|
12
13
|
|
14
|
+
def self.meta_id(*args)
|
15
|
+
Digest::SHA1.hexdigest([rand.to_s, self, args].join)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.perform(meta_id)
|
19
|
+
(0..4).each do |i|
|
20
|
+
at(i, 5, 'working')
|
21
|
+
end
|
22
|
+
at(5, 5, 'complete')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class IncludeBothJob
|
27
|
+
extend Resque::Plugins::Meta
|
28
|
+
extend Resque::Plugins::Progress
|
29
|
+
@queue = :test
|
30
|
+
|
31
|
+
def self.expire_meta_in
|
32
|
+
10
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.meta_id(*args)
|
36
|
+
Digest::SHA1.hexdigest([rand.to_s, self, args].join)
|
37
|
+
end
|
38
|
+
|
13
39
|
def self.perform(meta_id)
|
14
40
|
(0..4).each do |i|
|
15
41
|
at(i, 5, 'working')
|
@@ -17,6 +43,8 @@ class ProgressJob
|
|
17
43
|
at(5, 5, 'complete')
|
18
44
|
end
|
19
45
|
end
|
46
|
+
|
47
|
+
|
20
48
|
class ProgressTest < Test::Unit::TestCase
|
21
49
|
def setup
|
22
50
|
Resque.redis.flushall
|
@@ -67,4 +95,26 @@ class ProgressTest < Test::Unit::TestCase
|
|
67
95
|
assert_equal(100, meta.progress[:percent])
|
68
96
|
assert_equal('complete', meta.progress[:message])
|
69
97
|
end
|
98
|
+
|
99
|
+
def test_include_both
|
100
|
+
meta = IncludeBothJob.enqueue
|
101
|
+
assert_not_nil(meta)
|
102
|
+
assert_not_nil(meta.progress)
|
103
|
+
assert_equal(0, meta.progress[:num])
|
104
|
+
assert_equal(1, meta.progress[:total])
|
105
|
+
assert_equal(0, meta.progress[:percent])
|
106
|
+
assert_nil(meta.progress[:message])
|
107
|
+
|
108
|
+
worker = Resque::Worker.new(:test)
|
109
|
+
worker.work(0)
|
110
|
+
|
111
|
+
meta = IncludeBothJob.get_meta(meta.meta_id)
|
112
|
+
assert_not_nil(meta)
|
113
|
+
assert(meta.finished?)
|
114
|
+
assert_not_nil(meta.progress)
|
115
|
+
assert_equal(5, meta.progress[:num])
|
116
|
+
assert_equal(5, meta.progress[:total])
|
117
|
+
assert_equal(100, meta.progress[:percent])
|
118
|
+
assert_equal('complete', meta.progress[:message])
|
119
|
+
end
|
70
120
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-progress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Idris Mokhtarzada
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-25 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|