resque-igo 1.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/resque/errors.rb +3 -0
- data/lib/resque/failure/mongo.rb +40 -0
- data/lib/resque/job.rb +17 -1
- data/lib/resque/version.rb +1 -1
- data/lib/resque.rb +1 -1
- data/test/resque_test.rb +12 -22
- data/test/test_helper.rb +8 -1
- metadata +8 -7
data/lib/resque/errors.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Resque
|
2
|
+
module Failure
|
3
|
+
# A Failure backend that stores exceptions in Mongo. Very simple but
|
4
|
+
# works out of the box, along with support in the Resque web app.
|
5
|
+
class Mongo < Base
|
6
|
+
def save
|
7
|
+
data = {
|
8
|
+
:failed_at => Time.now.strftime("%Y/%m/%d %H:%M:%S"),
|
9
|
+
:payload => payload,
|
10
|
+
:exception => exception.class.to_s,
|
11
|
+
:error => exception.to_s,
|
12
|
+
:backtrace => Array(exception.backtrace),
|
13
|
+
:worker => worker.to_s,
|
14
|
+
:queue => queue
|
15
|
+
}
|
16
|
+
Resque.mongo_failures << data
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.count
|
20
|
+
Resque.mongo_failures.count
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.all(start = 0, count = 1)
|
24
|
+
all_failures = Resque.mongo_failures.find().skip(start).limit(count).to_a
|
25
|
+
# all_failures.size == 1 ? all_failures.first : all_failures
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.clear
|
29
|
+
Resque.mongo_failures.remove
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.requeue(index)
|
33
|
+
item = all(index)
|
34
|
+
item['retried_at'] = Time.now.strftime("%Y/%m/%d %H:%M:%S")
|
35
|
+
Resque.mongo_failures.update({ :_id => item['_id']}, item)
|
36
|
+
Job.create(item['queue'], item['payload']['class'], *item['payload']['args'])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/resque/job.rb
CHANGED
@@ -50,10 +50,26 @@ module Resque
|
|
50
50
|
end
|
51
51
|
|
52
52
|
item = { :class => klass.to_s, :args => args}
|
53
|
+
|
53
54
|
item[:_id] = args[0][:_id] if Resque.allows_unique_jobs(klass) && args[0].is_a?(Hash) && args[0].has_key?(:_id)
|
54
55
|
item[:unique] = true if item[:_id]
|
55
|
-
item[:delay_until] = args[0][:delay_until] if Resque.allows_delayed_jobs(klass) && args[0].is_a?(Hash) && args[0].has_key?(:delay_until)
|
56
56
|
|
57
|
+
#are we trying to put a non-delayed job into a delayed queue?
|
58
|
+
if Resque.queue_allows_delayed(queue)
|
59
|
+
if Resque.allows_delayed_jobs(klass)
|
60
|
+
if args[0].is_a?(Hash) && args[0].has_key?(:delay_until)
|
61
|
+
item[:delay_until] = args[0][:delay_until]
|
62
|
+
else
|
63
|
+
raise QueueError.new 'trying to insert delayed job without delay_until'
|
64
|
+
end
|
65
|
+
else
|
66
|
+
raise QueueError.new 'trying to insert non-delayed job into delayed queue'
|
67
|
+
end
|
68
|
+
else
|
69
|
+
if Resque.allows_delayed_jobs(klass)
|
70
|
+
raise QueueError.new 'trying to insert a delayed job into a non-delayed queue'
|
71
|
+
end
|
72
|
+
end
|
57
73
|
|
58
74
|
ret = Resque.push(queue, item)
|
59
75
|
Plugin.after_enqueue_hooks(klass).each do |hook|
|
data/lib/resque/version.rb
CHANGED
data/lib/resque.rb
CHANGED
@@ -247,7 +247,7 @@ module Resque
|
|
247
247
|
# Returns an array of all known Resque queues as strings.
|
248
248
|
def queues
|
249
249
|
names = mongo.collection_names
|
250
|
-
names.delete_if{ |name| name
|
250
|
+
names.delete_if{ |name| name =~ /system./ || name =~ /resque\./ }
|
251
251
|
end
|
252
252
|
|
253
253
|
# Given a queue name, completely deletes the queue.
|
data/test/resque_test.rb
CHANGED
@@ -325,27 +325,17 @@ context "Resque" do
|
|
325
325
|
Resque.bypass_queues = false
|
326
326
|
end
|
327
327
|
|
328
|
-
test "
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
Resque.enqueue(DelayedJob, args)
|
341
|
-
assert_equal(3, Resque.size(:delayed))
|
342
|
-
assert_equal(3, Resque.delayed_size(:delayed))
|
343
|
-
assert_equal(0, Resque.ready_size(:delayed))
|
344
|
-
Resque.enqueue(NonDelayedJob, args)
|
345
|
-
Resque.enqueue(NonDelayedJob, args)
|
346
|
-
Resque.enqueue(DelayedJob, args)
|
347
|
-
assert_equal(6, Resque.size(:delayed))
|
348
|
-
assert_equal(2, Resque.ready_size(:delayed))
|
349
|
-
assert_equal(4, Resque.delayed_size(:delayed))
|
328
|
+
test "mixing delay and non-delay is bad" do
|
329
|
+
dargs = { :delay_until => Time.new + 3600}
|
330
|
+
|
331
|
+
#non-delay into delay
|
332
|
+
assert_raise(Resque::QueueError) do
|
333
|
+
Resque.enqueue(NonDelayedJob, dargs)
|
334
|
+
end
|
335
|
+
|
336
|
+
#delay into non-delay
|
337
|
+
assert_raise(Resque::QueueError) do
|
338
|
+
Resque.enqueue(MistargetedDelayedJob, dargs)
|
339
|
+
end
|
350
340
|
end
|
351
341
|
end
|
data/test/test_helper.rb
CHANGED
@@ -100,7 +100,6 @@ end
|
|
100
100
|
class OtherUnique
|
101
101
|
@queue = :unique2
|
102
102
|
@unique_jobs = true
|
103
|
-
@delayed_jobs = true
|
104
103
|
end
|
105
104
|
|
106
105
|
class DelayedJob
|
@@ -112,6 +111,14 @@ class DelayedJob
|
|
112
111
|
end
|
113
112
|
end
|
114
113
|
|
114
|
+
class MistargetedDelayedJob
|
115
|
+
@queue = :unique
|
116
|
+
@delayed_jobs = true
|
117
|
+
def self.perform(data)
|
118
|
+
" mistargeteddelayed job executing #{data.inspect}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
115
122
|
class NonDelayedJob
|
116
123
|
@queue = :delayed
|
117
124
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-igo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Nathan D Acuff
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-28 00:00:00 -04:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -81,9 +82,8 @@ dependencies:
|
|
81
82
|
version: 1.0.7
|
82
83
|
type: :runtime
|
83
84
|
version_requirements: *id004
|
84
|
-
description: " Resque is a Redis-backed Ruby library for creating background jobs,\n placing those jobs on multiple queues, and processing them later.\n\n\
|
85
|
-
|
86
|
-
email: naginata@gmail.com
|
85
|
+
description: " Resque is a Redis-backed Ruby library for creating background jobs,\n placing those jobs on multiple queues, and processing them later.\n\n Resque-igo is the same thing, but for mongo. It would not exist without the work of defunkt and ctrochalakis on github.\n\n Background jobs can be any Ruby class or module that responds to\n perform. Your existing classes can easily be converted to background\n jobs or you can create new classes specifically to do work. Or, you\n can do both.\n\n Resque is heavily inspired by DelayedJob (which rocks) and is\n comprised of three parts:\n\n * A Ruby library for creating, querying, and processing jobs\n * A Rake task for starting a worker which processes jobs\n * A Sinatra app for monitoring queues, jobs, and workers.\n"
|
86
|
+
email: nacuff@igodigital.com
|
87
87
|
executables:
|
88
88
|
- resque
|
89
89
|
- resque-web
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/resque/errors.rb
|
101
101
|
- lib/resque/failure/base.rb
|
102
102
|
- lib/resque/failure/hoptoad.rb
|
103
|
+
- lib/resque/failure/mongo.rb
|
103
104
|
- lib/resque/failure/multiple.rb
|
104
105
|
- lib/resque/failure/redis.rb
|
105
106
|
- lib/resque/failure.rb
|
@@ -143,7 +144,7 @@ files:
|
|
143
144
|
- test/worker_test.rb
|
144
145
|
- tasks/resque.rake
|
145
146
|
has_rdoc: true
|
146
|
-
homepage: http://github.com/
|
147
|
+
homepage: http://github.com/mediocretes/resque-mongo
|
147
148
|
licenses: []
|
148
149
|
|
149
150
|
post_install_message:
|