resque-pertry 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -38,6 +38,7 @@ module Resque
|
|
38
38
|
def finnish_job(klass, args)
|
39
39
|
with_job(klass, args) do |job|
|
40
40
|
return unless job
|
41
|
+
return if job.finnished?
|
41
42
|
job.update_attribute(:completed_at, Time.now)
|
42
43
|
end
|
43
44
|
end
|
@@ -45,6 +46,7 @@ module Resque
|
|
45
46
|
def trying_job(klass, args)
|
46
47
|
with_job(klass, args) do |job|
|
47
48
|
return unless job
|
49
|
+
return if job.finnished?
|
48
50
|
job.update_attributes( :last_tried_at => Time.now,
|
49
51
|
:attempt => job.attempt + 1)
|
50
52
|
end
|
@@ -53,6 +55,7 @@ module Resque
|
|
53
55
|
def fail_job(klass, args)
|
54
56
|
with_job(klass, args) do |job|
|
55
57
|
return unless job
|
58
|
+
return if job.finnished?
|
56
59
|
job.update_attribute(:failed_at, Time.now)
|
57
60
|
end
|
58
61
|
end
|
@@ -74,9 +77,21 @@ module Resque
|
|
74
77
|
|
75
78
|
end
|
76
79
|
|
77
|
-
def
|
80
|
+
def completed?
|
78
81
|
completed_at
|
79
82
|
end
|
83
|
+
|
84
|
+
def expired?
|
85
|
+
expires_at < Time.now
|
86
|
+
end
|
87
|
+
|
88
|
+
def failed?
|
89
|
+
failed_at
|
90
|
+
end
|
91
|
+
|
92
|
+
def finnished?
|
93
|
+
completed? || failed? || expired?
|
94
|
+
end
|
80
95
|
|
81
96
|
def payload
|
82
97
|
@payload ||= Resque.decode(arguments)
|
data/lib/resque/pertry/retry.rb
CHANGED
@@ -102,7 +102,7 @@ module Resque
|
|
102
102
|
def retry?(model, exception)
|
103
103
|
# check the obvious
|
104
104
|
return false unless model
|
105
|
-
return false if model.
|
105
|
+
return false if model.finnished?
|
106
106
|
|
107
107
|
# job has used up all it's allowed attempts
|
108
108
|
return false if max_attempt_reached?(model)
|
@@ -110,9 +110,6 @@ module Resque
|
|
110
110
|
# job exception is not whitelisted for retries
|
111
111
|
return false unless exception_whitelisted?(model, exception)
|
112
112
|
|
113
|
-
# job has expired
|
114
|
-
return false if ttl_expired?(model)
|
115
|
-
|
116
113
|
# seems like we should be able to retry this job
|
117
114
|
return true
|
118
115
|
end
|
@@ -138,7 +135,7 @@ module Resque
|
|
138
135
|
# if we didn't set a ttl, it hasn't expired
|
139
136
|
return false unless self.class.retry_ttl
|
140
137
|
|
141
|
-
model.
|
138
|
+
model.expired?
|
142
139
|
end
|
143
140
|
|
144
141
|
def max_attempt_reached?(model)
|
@@ -6,6 +6,8 @@ module Resque
|
|
6
6
|
include Resque::Pertry::Persistence
|
7
7
|
include Resque::Pertry::Retry
|
8
8
|
|
9
|
+
attr_reader :exception_handled
|
10
|
+
|
9
11
|
class << self
|
10
12
|
|
11
13
|
# Enqueue a job
|
@@ -23,7 +25,13 @@ module Resque
|
|
23
25
|
def perform(args = {})
|
24
26
|
raise ArgumentError, "Invalid arguments, expecting a Hash but got: #{args.inspect}" unless Hash === args
|
25
27
|
|
26
|
-
|
28
|
+
begin
|
29
|
+
job = instance(args)
|
30
|
+
job.perform
|
31
|
+
rescue => e
|
32
|
+
job.handle_exception(e)
|
33
|
+
raise unless job.exception_handled
|
34
|
+
end
|
27
35
|
end
|
28
36
|
|
29
37
|
def instance(args = {})
|
@@ -88,6 +96,31 @@ module Resque
|
|
88
96
|
raise NoMethodError, "No method #{self.class.name}#perform defined!"
|
89
97
|
end
|
90
98
|
|
99
|
+
def handle_exception(exception)
|
100
|
+
# we don't handle exceptions by default, leave it for resque
|
101
|
+
# when overridding this method, if you decide you want to completely
|
102
|
+
# handle it, and not pass it back to resque, you'll need to call
|
103
|
+
# exception_handled!
|
104
|
+
end
|
105
|
+
|
106
|
+
def exception_handled
|
107
|
+
@exception_handled ||= false
|
108
|
+
end
|
109
|
+
|
110
|
+
def exception_handled!
|
111
|
+
@exception_handled = true
|
112
|
+
end
|
113
|
+
|
114
|
+
# mark job as failed, won't be retried
|
115
|
+
def fail!
|
116
|
+
Resque::Pertry::ResquePertryPersistence.fail_job(self.class, payload)
|
117
|
+
end
|
118
|
+
|
119
|
+
# mark job as complete
|
120
|
+
def complete!
|
121
|
+
Resque::Pertry::ResquePertryPersistence.finnish_job(self.class, payload)
|
122
|
+
end
|
123
|
+
|
91
124
|
def arguments
|
92
125
|
@_arguments
|
93
126
|
end
|
data/resque-pertry.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "resque-pertry"
|
3
3
|
s.description = "Adds persistence to Resque jobs, and retry properties"
|
4
|
-
s.version = "1.0.
|
4
|
+
s.version = "1.0.1"
|
5
5
|
s.authors = [ "Anthony Powles" ]
|
6
6
|
s.email = "rubygems+resque-pertry@idreamz.net"
|
7
7
|
s.summary = "Allows job to be persistent, and be retried in case of failure"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-pertry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|