resque-status 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_helper.rb CHANGED
@@ -6,8 +6,7 @@ require 'rubygems'
6
6
  require 'shoulda'
7
7
  require 'mocha'
8
8
 
9
- require 'resque/status'
10
- require 'resque/job_with_status'
9
+ require 'resque-status'
11
10
 
12
11
  class Test::Unit::TestCase
13
12
  end
@@ -45,12 +44,14 @@ end
45
44
 
46
45
  puts "Starting redis for testing at localhost:9736..."
47
46
  `redis-server #{dir}/redis-test.conf`
48
- Resque.redis = 'localhost:9736'
49
- Redisk.redis = 'localhost:9736'
47
+ Resque.redis = 'localhost:9736/1'
48
+ Redisk.redis = 'localhost:9736/1'
50
49
 
51
50
  #### Fixtures
52
51
 
53
- class WorkingJob < Resque::JobWithStatus
52
+ class WorkingJob
53
+
54
+ include Resque::Plugins::Status
54
55
 
55
56
  def perform
56
57
  total = options['num']
@@ -61,7 +62,9 @@ class WorkingJob < Resque::JobWithStatus
61
62
 
62
63
  end
63
64
 
64
- class ErrorJob < Resque::JobWithStatus
65
+ class ErrorJob
66
+
67
+ include Resque::Plugins::Status
65
68
 
66
69
  def perform
67
70
  raise "I'm a bad little job"
@@ -69,7 +72,9 @@ class ErrorJob < Resque::JobWithStatus
69
72
 
70
73
  end
71
74
 
72
- class KillableJob < Resque::JobWithStatus
75
+ class KillableJob
76
+
77
+ include Resque::Plugins::Status
73
78
 
74
79
  def perform
75
80
  Resque.redis.set("#{uuid}:iterations", 0)
@@ -80,3 +85,7 @@ class KillableJob < Resque::JobWithStatus
80
85
  end
81
86
 
82
87
  end
88
+
89
+ class BasicJob
90
+ include Resque::Plugins::Status
91
+ end
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
- class TestResqueJobWithStatus < Test::Unit::TestCase
3
+ class TestResquePluginsStatus < Test::Unit::TestCase
4
4
 
5
- context "Resque::JobWithStatus" do
5
+ context "Resque::Plugins::Status" do
6
6
  setup do
7
7
  Resque.redis.flushall
8
8
  end
@@ -23,7 +23,7 @@ class TestResqueJobWithStatus < Test::Unit::TestCase
23
23
  end
24
24
 
25
25
  should "add the uuid to the statuses" do
26
- assert_contains Resque::Status.status_ids, @uuid
26
+ assert_contains Resque::Plugins::Status::Hash.status_ids, @uuid
27
27
  end
28
28
 
29
29
  should "return a UUID" do
@@ -48,7 +48,7 @@ class TestResqueJobWithStatus < Test::Unit::TestCase
48
48
 
49
49
  context ".enqueue" do
50
50
  setup do
51
- @uuid = Resque::JobWithStatus.enqueue(WorkingJob, :num => 100)
51
+ @uuid = BasicJob.enqueue(WorkingJob, :num => 100)
52
52
  @payload = Resque.pop(:statused)
53
53
  end
54
54
 
@@ -61,7 +61,7 @@ class TestResqueJobWithStatus < Test::Unit::TestCase
61
61
  end
62
62
 
63
63
  should "add the uuid to the statuses" do
64
- assert_contains Resque::Status.status_ids, @uuid
64
+ assert_contains Resque::Plugins::Status::Hash.status_ids, @uuid
65
65
  end
66
66
 
67
67
  should "return UUID" do
@@ -86,7 +86,7 @@ class TestResqueJobWithStatus < Test::Unit::TestCase
86
86
  end
87
87
 
88
88
  should "set the status" do
89
- assert @performed.status.is_a?(Resque::Status)
89
+ assert @performed.status.is_a?(Resque::Plugins::Status::Hash)
90
90
  assert_equal 'WorkingJob({"num"=>100})', @performed.status.name
91
91
  end
92
92
 
@@ -100,10 +100,10 @@ class TestResqueJobWithStatus < Test::Unit::TestCase
100
100
  setup do
101
101
  @uuid = KillableJob.create(:num => 100)
102
102
  @payload = Resque.pop(:statused)
103
- Resque::Status.kill(@uuid)
104
- assert_contains Resque::Status.kill_ids, @uuid
103
+ Resque::Plugins::Status::Hash.kill(@uuid)
104
+ assert_contains Resque::Plugins::Status::Hash.kill_ids, @uuid
105
105
  @performed = KillableJob.perform(*@payload['args'])
106
- @status = Resque::Status.get(@uuid)
106
+ @status = Resque::Plugins::Status::Hash.get(@uuid)
107
107
  end
108
108
 
109
109
  should "set the status to killed" do
@@ -117,10 +117,94 @@ class TestResqueJobWithStatus < Test::Unit::TestCase
117
117
  end
118
118
 
119
119
  should "not persist the kill key" do
120
- assert_does_not_contain Resque::Status.kill_ids, @uuid
120
+ assert_does_not_contain Resque::Plugins::Status::Hash.kill_ids, @uuid
121
121
  end
122
122
  end
123
123
 
124
+ context "killing all jobs" do
125
+ setup do
126
+ @uuid1 = KillableJob.create(:num => 100)
127
+ @uuid2 = KillableJob.create(:num => 100)
128
+
129
+ Resque::Status.killall
130
+
131
+ assert_contains Resque::Status.kill_ids, @uuid1
132
+ assert_contains Resque::Status.kill_ids, @uuid2
133
+
134
+ @payload1 = Resque.pop(:statused)
135
+ @payload2 = Resque.pop(:statused)
136
+
137
+ @performed = KillableJob.perform(*@payload1['args'])
138
+ @performed = KillableJob.perform(*@payload2['args'])
139
+
140
+ @status1 = Resque::Status.get(@uuid1)
141
+ @status2 = Resque::Status.get(@uuid2)
142
+ end
143
+
144
+ should "set the status to killed" do
145
+ assert_equal 'killed', @status1.status
146
+ assert @status1.killed?
147
+ assert !@status1.completed?
148
+
149
+ assert_equal 'killed', @status2.status
150
+ assert @status2.killed?
151
+ assert !@status2.completed?
152
+ end
153
+
154
+ should "only perform iterations up to kill" do
155
+ assert_equal 1, Resque.redis.get("#{@uuid1}:iterations").to_i
156
+ assert_equal 1, Resque.redis.get("#{@uuid2}:iterations").to_i
157
+ end
158
+
159
+ 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
162
+ end
163
+
164
+ end
165
+
166
+ context "invoking killall jobs to kill a range" do
167
+ setup do
168
+ @uuid1 = KillableJob.create(:num => 100)
169
+ @uuid2 = KillableJob.create(:num => 100)
170
+
171
+ Resque::Status.killall(0,0) # only @uuid2 should be killed
172
+
173
+ assert_does_not_contain Resque::Status.kill_ids, @uuid1
174
+ assert_contains Resque::Status.kill_ids, @uuid2
175
+
176
+ @payload1 = Resque.pop(:statused)
177
+ @payload2 = Resque.pop(:statused)
178
+
179
+ @performed = KillableJob.perform(*@payload1['args'])
180
+ @performed = KillableJob.perform(*@payload2['args'])
181
+
182
+ @status1 = Resque::Status.get(@uuid1)
183
+ @status2 = Resque::Status.get(@uuid2)
184
+ end
185
+
186
+ should "set the status to killed" do
187
+ assert_equal 'completed', @status1.status
188
+ assert !@status1.killed?
189
+ assert @status1.completed?
190
+
191
+ assert_equal 'killed', @status2.status
192
+ assert @status2.killed?
193
+ assert !@status2.completed?
194
+ end
195
+
196
+ should "only perform iterations up to kill" do
197
+ assert_equal 100, Resque.redis.get("#{@uuid1}:iterations").to_i
198
+ assert_equal 1, Resque.redis.get("#{@uuid2}:iterations").to_i
199
+ end
200
+
201
+ 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
204
+ end
205
+
206
+ end
207
+
124
208
  context "with an invoked job" do
125
209
  setup do
126
210
  @job = WorkingJob.new('123', {'num' => 100})
@@ -0,0 +1,153 @@
1
+ require 'test_helper'
2
+
3
+ class TestResquePluginsStatusHash < Test::Unit::TestCase
4
+
5
+ context "Resque::Plugins::Status::Hash" do
6
+ setup do
7
+ Resque.redis.flushall
8
+ Resque::Plugins::Status::Hash.expire_in = nil
9
+ @uuid = Resque::Plugins::Status::Hash.create
10
+ Resque::Plugins::Status::Hash.set(@uuid, "my status")
11
+ @uuid_with_json = Resque::Plugins::Status::Hash.create({"im" => "json"})
12
+ end
13
+
14
+ context ".get" do
15
+ should "return the status as a Resque::Plugins::Status::Hash for the uuid" do
16
+ status = Resque::Plugins::Status::Hash.get(@uuid)
17
+ assert status.is_a?(Resque::Plugins::Status::Hash)
18
+ assert_equal 'my status', status.message
19
+ end
20
+
21
+ should "return false if the status is not set" do
22
+ assert !Resque::Plugins::Status::Hash.get('whu')
23
+ end
24
+
25
+ should "decode encoded json" do
26
+ assert_equal("json", Resque::Plugins::Status::Hash.get(@uuid_with_json)['im'])
27
+ end
28
+ end
29
+
30
+ context ".set" do
31
+
32
+ should "set the status for the uuid" do
33
+ assert Resque::Plugins::Status::Hash.set(@uuid, "updated")
34
+ assert_equal "updated", Resque::Plugins::Status::Hash.get(@uuid).message
35
+ end
36
+
37
+ should "return the status" do
38
+ assert Resque::Plugins::Status::Hash.set(@uuid, "updated").is_a?(Resque::Plugins::Status::Hash)
39
+ end
40
+
41
+ end
42
+
43
+ context ".create" do
44
+ should "add an item to a key set" do
45
+ before = Resque::Plugins::Status::Hash.status_ids.length
46
+ Resque::Plugins::Status::Hash.create
47
+ after = Resque::Plugins::Status::Hash.status_ids.length
48
+ assert_equal 1, after - before
49
+ end
50
+
51
+ should "return a uuid" do
52
+ assert_match(/^\w{32}$/, Resque::Plugins::Status::Hash.create)
53
+ end
54
+
55
+ should "store any status passed" do
56
+ uuid = Resque::Plugins::Status::Hash.create("initial status")
57
+ status = Resque::Plugins::Status::Hash.get(uuid)
58
+ assert status.is_a?(Resque::Plugins::Status::Hash)
59
+ assert_equal "initial status", status.message
60
+ end
61
+
62
+ should "expire keys if expire_in is set" do
63
+ Resque::Plugins::Status::Hash.expire_in = 1
64
+ uuid = Resque::Plugins::Status::Hash.create("new status")
65
+ assert_contains Resque::Plugins::Status::Hash.status_ids, uuid
66
+ assert_equal "new status", Resque::Plugins::Status::Hash.get(uuid).message
67
+ sleep 2
68
+ Resque::Plugins::Status::Hash.create
69
+ assert_does_not_contain Resque::Plugins::Status::Hash.status_ids, uuid
70
+ assert_nil Resque::Plugins::Status::Hash.get(uuid)
71
+ end
72
+
73
+ should "store the options for the job created" do
74
+ uuid = Resque::Plugins::Status::Hash.create("new", :options => {'test' => '123'})
75
+ assert uuid
76
+ status = Resque::Plugins::Status::Hash.get(uuid)
77
+ assert status.is_a?(Resque::Plugins::Status::Hash)
78
+ assert_equal '123', status.options['test']
79
+ end
80
+ end
81
+
82
+ context ".clear" do
83
+ setup do
84
+ Resque::Plugins::Status::Hash.clear
85
+ end
86
+
87
+ should "clear any statuses" do
88
+ assert_nil Resque::Plugins::Status::Hash.get(@uuid)
89
+ end
90
+
91
+ should "clear any recent statuses" do
92
+ assert Resque::Plugins::Status::Hash.status_ids.empty?
93
+ end
94
+
95
+ end
96
+
97
+ context ".status_ids" do
98
+
99
+ setup do
100
+ @uuids = []
101
+ 30.times{ Resque::Plugins::Status::Hash.create }
102
+ end
103
+
104
+ should "return an array of job ids" do
105
+ assert Resque::Plugins::Status::Hash.status_ids.is_a?(Array)
106
+ assert_equal 32, Resque::Plugins::Status::Hash.status_ids.size # 30 + 2
107
+ end
108
+
109
+ should "let you paginate through the statuses" do
110
+ assert_equal Resque::Plugins::Status::Hash.status_ids[0, 10], Resque::Plugins::Status::Hash.status_ids(0, 9)
111
+ assert_equal Resque::Plugins::Status::Hash.status_ids[10, 10], Resque::Plugins::Status::Hash.status_ids(10, 19)
112
+ # assert_equal Resque::Plugins::Status::Hash.status_ids.reverse[0, 10], Resque::Plugins::Status::Hash.status_ids(0, 10)
113
+ end
114
+ end
115
+
116
+ context ".statuses" do
117
+
118
+ should "return an array status objects" do
119
+ statuses = Resque::Plugins::Status::Hash.statuses
120
+ assert statuses.is_a?(Array)
121
+ assert_same_elements [@uuid_with_json, @uuid], statuses.collect {|s| s.uuid }
122
+ end
123
+
124
+ end
125
+
126
+ # context ".count" do
127
+ #
128
+ # should "return a count of statuses" do
129
+ # statuses = Resque::Plugins::Status::Hash.statuses
130
+ # assert_equal 2, statuses.size
131
+ # assert_equal statuses.size, Resque::Plugins::Status::Hash.count
132
+ # end
133
+ #
134
+ # end
135
+
136
+ context ".logger" do
137
+ setup do
138
+ @logger = Resque::Plugins::Status::Hash.logger(@uuid)
139
+ end
140
+
141
+ should "return a redisk logger" do
142
+ assert @logger.is_a?(Redisk::Logger)
143
+ end
144
+
145
+ should "scope the logger to a key" do
146
+ assert_match(/#{@uuid}/, @logger.name)
147
+ end
148
+
149
+ end
150
+
151
+ end
152
+
153
+ 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.2.4
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,77 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-10 00:00:00.000000000 -07:00
13
- default_executable:
12
+ date: 2012-01-22 00:00:00.000000000Z
14
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redisk
16
+ requirement: &70167507502960 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70167507502960
25
+ - !ruby/object:Gem::Dependency
26
+ name: resque
27
+ requirement: &70167507502380 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.3.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70167507502380
36
+ - !ruby/object:Gem::Dependency
37
+ name: uuid
38
+ requirement: &70167507501840 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.2
44
+ type: :runtime
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
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &70167507500200 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70167507500200
15
80
  - !ruby/object:Gem::Dependency
16
81
  name: uuid
17
- requirement: &2169498020 !ruby/object:Gem::Requirement
82
+ requirement: &70167507499640 !ruby/object:Gem::Requirement
18
83
  none: false
19
84
  requirements:
20
85
  - - ! '>='
@@ -22,10 +87,10 @@ dependencies:
22
87
  version: 2.0.2
23
88
  type: :runtime
24
89
  prerelease: false
25
- version_requirements: *2169498020
90
+ version_requirements: *70167507499640
26
91
  - !ruby/object:Gem::Dependency
27
92
  name: resque
28
- requirement: &2169496540 !ruby/object:Gem::Requirement
93
+ requirement: &70167507499060 !ruby/object:Gem::Requirement
29
94
  none: false
30
95
  requirements:
31
96
  - - ! '>='
@@ -33,10 +98,10 @@ dependencies:
33
98
  version: 1.3.1
34
99
  type: :runtime
35
100
  prerelease: false
36
- version_requirements: *2169496540
101
+ version_requirements: *70167507499060
37
102
  - !ruby/object:Gem::Dependency
38
103
  name: redisk
39
- requirement: &2169495360 !ruby/object:Gem::Requirement
104
+ requirement: &70167507496920 !ruby/object:Gem::Requirement
40
105
  none: false
41
106
  requirements:
42
107
  - - ! '>='
@@ -44,10 +109,10 @@ dependencies:
44
109
  version: 0.2.1
45
110
  type: :runtime
46
111
  prerelease: false
47
- version_requirements: *2169495360
112
+ version_requirements: *70167507496920
48
113
  - !ruby/object:Gem::Dependency
49
114
  name: shoulda
50
- requirement: &2169493900 !ruby/object:Gem::Requirement
115
+ requirement: &70167507496200 !ruby/object:Gem::Requirement
51
116
  none: false
52
117
  requirements:
53
118
  - - ! '>='
@@ -55,10 +120,10 @@ dependencies:
55
120
  version: 2.10.2
56
121
  type: :development
57
122
  prerelease: false
58
- version_requirements: *2169493900
123
+ version_requirements: *70167507496200
59
124
  - !ruby/object:Gem::Dependency
60
125
  name: mocha
61
- requirement: &2169493000 !ruby/object:Gem::Requirement
126
+ requirement: &70167507495300 !ruby/object:Gem::Requirement
62
127
  none: false
63
128
  requirements:
64
129
  - - ! '>='
@@ -66,11 +131,11 @@ dependencies:
66
131
  version: 0.9.8
67
132
  type: :development
68
133
  prerelease: false
69
- version_requirements: *2169493000
134
+ version_requirements: *70167507495300
70
135
  description: resque-status is an extension to the resque queue system that provides
71
- simple trackable jobs. It provides a Resque::Status class which can set/get the
72
- statuses of jobs and a Resque::JobWithStatus class that when subclassed provides
73
- easily trackable/killable jobs.
136
+ simple trackable jobs. It provides a Resque::Plugins::Status::Hash class which can
137
+ set/get the statuses of jobs and a Resque::Plugins::Status class that when included
138
+ provides easily trackable/killable jobs.
74
139
  email: aaron@quirkey.com
75
140
  executables: []
76
141
  extensions: []
@@ -79,12 +144,17 @@ extra_rdoc_files:
79
144
  - README.rdoc
80
145
  files:
81
146
  - .document
147
+ - Gemfile
148
+ - Gemfile.lock
82
149
  - LICENSE
83
150
  - README.rdoc
84
151
  - Rakefile
85
152
  - examples/sleep_job.rb
86
153
  - init.rb
154
+ - lib/resque-status.rb
87
155
  - lib/resque/job_with_status.rb
156
+ - lib/resque/plugins/status.rb
157
+ - lib/resque/plugins/status/hash.rb
88
158
  - lib/resque/server/views/status.erb
89
159
  - lib/resque/server/views/status_styles.erb
90
160
  - lib/resque/server/views/statuses.erb
@@ -93,9 +163,8 @@ files:
93
163
  - resque-status.gemspec
94
164
  - test/redis-test.conf
95
165
  - test/test_helper.rb
96
- - test/test_resque-job_with_status.rb
97
- - test/test_resque-status.rb
98
- has_rdoc: true
166
+ - test/test_resque_plugins_status.rb
167
+ - test/test_resque_plugins_status_hash.rb
99
168
  homepage: http://github.com/quirkey/resque-status
100
169
  licenses: []
101
170
  post_install_message:
@@ -116,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
185
  version: '0'
117
186
  requirements: []
118
187
  rubyforge_project: quirkey
119
- rubygems_version: 1.6.2
188
+ rubygems_version: 1.8.10
120
189
  signing_key:
121
190
  specification_version: 3
122
191
  summary: resque-status is an extension to the resque queue system that provides simple