resque-meta 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/lib/resque/plugins/meta/metadata.rb +12 -8
- data/lib/resque/plugins/meta/version.rb +1 -1
- data/lib/resque/plugins/meta.rb +1 -0
- data/test/meta_test.rb +15 -1
- metadata +7 -6
data/README.md
CHANGED
@@ -20,6 +20,7 @@ module Resque
|
|
20
20
|
@expire_in = @job_class.expire_meta_in || 0
|
21
21
|
end
|
22
22
|
|
23
|
+
# Reload the metadata from the store
|
23
24
|
def reload!
|
24
25
|
if new_meta = job_class.get_meta(meta_id)
|
25
26
|
@data = new_meta.data
|
@@ -27,6 +28,7 @@ module Resque
|
|
27
28
|
self
|
28
29
|
end
|
29
30
|
|
31
|
+
# Save the metadata
|
30
32
|
def save
|
31
33
|
job_class.store_meta(self)
|
32
34
|
self
|
@@ -41,22 +43,24 @@ module Resque
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def start!
|
44
|
-
|
46
|
+
@started_at = Time.now
|
47
|
+
self['started_at'] = to_time_format_str(@started_at)
|
45
48
|
save
|
46
49
|
end
|
47
50
|
|
48
51
|
def started_at
|
49
|
-
from_time_format_str('started_at')
|
52
|
+
@started_at ||= from_time_format_str('started_at')
|
50
53
|
end
|
51
54
|
|
52
55
|
def finish!
|
53
56
|
data['succeeded'] = true unless data.has_key?('succeeded')
|
54
|
-
|
57
|
+
@finished_at = Time.now
|
58
|
+
self['finished_at'] = to_time_format_str(@finished_at)
|
55
59
|
save
|
56
60
|
end
|
57
61
|
|
58
62
|
def finished_at
|
59
|
-
from_time_format_str('finished_at')
|
63
|
+
@finished_at ||= from_time_format_str('finished_at')
|
60
64
|
end
|
61
65
|
|
62
66
|
def expire_at
|
@@ -68,11 +72,11 @@ module Resque
|
|
68
72
|
end
|
69
73
|
|
70
74
|
def enqueued?
|
71
|
-
|
75
|
+
!started?
|
72
76
|
end
|
73
77
|
|
74
78
|
def working?
|
75
|
-
|
79
|
+
started? && !finished?
|
76
80
|
end
|
77
81
|
|
78
82
|
def started?
|
@@ -97,12 +101,12 @@ module Resque
|
|
97
101
|
end
|
98
102
|
|
99
103
|
def seconds_enqueued
|
100
|
-
(
|
104
|
+
(started_at || Time.now).to_f - enqueued_at.to_f
|
101
105
|
end
|
102
106
|
|
103
107
|
def seconds_processing
|
104
108
|
if started?
|
105
|
-
(
|
109
|
+
(finished_at || Time.now).to_f - started_at.to_f
|
106
110
|
else
|
107
111
|
0
|
108
112
|
end
|
data/lib/resque/plugins/meta.rb
CHANGED
@@ -24,6 +24,7 @@ module Resque
|
|
24
24
|
# meta0.enqueued_at # => 'Wed May 19 13:42:41 -0600 2010'
|
25
25
|
# meta0.meta_id # => '03c9e1a045ad012dd20500264a19273c'
|
26
26
|
# meta0['foo'] = 'bar' # => 'bar'
|
27
|
+
# meta0.save
|
27
28
|
#
|
28
29
|
# # later
|
29
30
|
# meta1 = MyJob.get_meta('03c9e1a045ad012dd20500264a19273c')
|
data/test/meta_test.rb
CHANGED
@@ -55,7 +55,7 @@ class MetaTest < Test::Unit::TestCase
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_meta_version
|
58
|
-
assert_equal '1.0.
|
58
|
+
assert_equal '1.0.3', Resque::Plugins::Meta::Version
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_lint
|
@@ -76,8 +76,10 @@ class MetaTest < Test::Unit::TestCase
|
|
76
76
|
assert_not_nil meta
|
77
77
|
assert_not_nil meta.meta_id
|
78
78
|
assert meta.enqueued_at.to_f > now.to_f, "#{meta.enqueued_at} should be after #{now}"
|
79
|
+
assert meta.seconds_enqueued > 0.0, "seconds_enqueued should be greater than zero"
|
79
80
|
assert meta.enqueued?
|
80
81
|
assert !meta.started?
|
82
|
+
assert_equal 0, meta.seconds_processing
|
81
83
|
assert !meta.finished?
|
82
84
|
assert_nil meta['foo']
|
83
85
|
assert_equal Resque::Plugins::Meta::Metadata, meta.class
|
@@ -96,6 +98,8 @@ class MetaTest < Test::Unit::TestCase
|
|
96
98
|
assert meta.finished?, 'Job should be finished'
|
97
99
|
assert meta.succeeded?, 'Job should have succeeded'
|
98
100
|
assert !meta.enqueued?
|
101
|
+
assert meta.seconds_enqueued > 0.0, "seconds_enqueued should be greater than zero"
|
102
|
+
assert meta.seconds_processing > 0.0, "seconds_processing should be greater than zero"
|
99
103
|
assert_equal 'bar', meta['foo'], "'foo' not found in #{meta.inspect}"
|
100
104
|
end
|
101
105
|
|
@@ -152,4 +156,14 @@ class MetaTest < Test::Unit::TestCase
|
|
152
156
|
assert meta.failed?
|
153
157
|
assert !meta.succeeded?
|
154
158
|
end
|
159
|
+
|
160
|
+
def test_saving_additional_metadata
|
161
|
+
meta = MetaJob.enqueue('stuff')
|
162
|
+
meta['foo'] = 'bar'
|
163
|
+
meta.save
|
164
|
+
|
165
|
+
# later
|
166
|
+
meta = MetaJob.get_meta(meta.meta_id)
|
167
|
+
assert_equal 'bar', meta['foo']
|
168
|
+
end
|
155
169
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-meta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lee Marlow
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-10 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -53,6 +53,7 @@ description: |
|
|
53
53
|
meta0.enqueued_at # => 'Wed May 19 13:42:41 -0600 2010'
|
54
54
|
meta0.meta_id # => '03c9e1a045ad012dd20500264a19273c'
|
55
55
|
meta0['foo'] = 'bar' # => 'bar'
|
56
|
+
meta0.save
|
56
57
|
|
57
58
|
# later
|
58
59
|
meta1 = MyJob.get_meta('03c9e1a045ad012dd20500264a19273c')
|
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
requirements: []
|
109
110
|
|
110
111
|
rubyforge_project:
|
111
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.4.2
|
112
113
|
signing_key:
|
113
114
|
specification_version: 3
|
114
115
|
summary: A Resque plugin for storing job metadata.
|