resque-job_history 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/resque/plugins/job_history/job.rb +10 -1
- data/lib/resque/plugins/job_history.rb +37 -1
- data/lib/resque/plugins/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4301532dbe01fd400f2fdd276beab3a790ab5f4
|
4
|
+
data.tar.gz: 885590015fe0fda02175694da4b1e6e3fdfc75cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fad42f3ef35691176c320fe33a5c55023664b0c29dbac8484982f86fd2c9e784097bc4be5d8e98ff74c309aa576182c295c27294ceac64bbc7dbf0d266ddda75
|
7
|
+
data.tar.gz: 8d1d05c15bd9f3ac0f9b277737862913b45483d837bd417dc8e99b75dbbf6deea56fbdf8231ee38ea1b829fe4553bed8192fd9ec92c9911410b59e6f568ef39e
|
@@ -70,7 +70,7 @@ module Resque
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def failed(exception)
|
73
|
-
redis.hset(job_key, "error", exception
|
73
|
+
redis.hset(job_key, "error", exception_message(exception))
|
74
74
|
redis.incr(total_failed_key)
|
75
75
|
|
76
76
|
finish
|
@@ -113,6 +113,15 @@ module Resque
|
|
113
113
|
|
114
114
|
private
|
115
115
|
|
116
|
+
def exception_message(exception)
|
117
|
+
if exception.is_a?(Resque::DirtyExit)
|
118
|
+
("#{exception.message}\n\n#{exception.process_status&.message}\n\n" +
|
119
|
+
Array.wrap(exception.process_status&.backtrace).join("\n")).strip
|
120
|
+
else
|
121
|
+
exception.message
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
116
125
|
def remove_from_job_lists
|
117
126
|
running_jobs.remove_job(job_id)
|
118
127
|
finished_jobs.remove_job(job_id)
|
@@ -38,8 +38,22 @@ module Resque
|
|
38
38
|
# The class methods added to the job class that is being enqueued and whose history is to be
|
39
39
|
# recorded.
|
40
40
|
module ClassMethods
|
41
|
+
def on_failure_job_history(error, *args)
|
42
|
+
job_class_name = active_job_class_name(*args)
|
43
|
+
job_args = *active_job_args(*args)
|
44
|
+
|
45
|
+
failed_job = find_failed_job(job_args, job_class_name)
|
46
|
+
|
47
|
+
return unless failed_job
|
48
|
+
return if failed_job.finished? && failed_job.error.present?
|
49
|
+
|
50
|
+
failed_job.failed(error)
|
51
|
+
end
|
52
|
+
|
41
53
|
def around_perform_job_history(*args)
|
42
|
-
running_job
|
54
|
+
running_job = Resque::Plugins::JobHistory::Job.new(active_job_class_name(*args),
|
55
|
+
SecureRandom.uuid)
|
56
|
+
self.most_recent_job = running_job
|
43
57
|
|
44
58
|
begin
|
45
59
|
running_job.start(*active_job_args(*args))
|
@@ -52,6 +66,7 @@ module Resque
|
|
52
66
|
raise
|
53
67
|
ensure
|
54
68
|
running_job.cancel unless running_job.finished? || running_job.error
|
69
|
+
self.most_recent_job = nil
|
55
70
|
end
|
56
71
|
end
|
57
72
|
|
@@ -75,6 +90,14 @@ module Resque
|
|
75
90
|
Resque::Plugins::JobHistory::HistoryDetails.new(name)
|
76
91
|
end
|
77
92
|
|
93
|
+
def most_recent_job=(job)
|
94
|
+
@most_recent_job = job
|
95
|
+
end
|
96
|
+
|
97
|
+
def most_recent_job
|
98
|
+
@most_recent_job
|
99
|
+
end
|
100
|
+
|
78
101
|
private
|
79
102
|
|
80
103
|
def job_class_has_history?(*args)
|
@@ -103,6 +126,19 @@ module Resque
|
|
103
126
|
args
|
104
127
|
end
|
105
128
|
end
|
129
|
+
|
130
|
+
def find_failed_job(job_args, job_class_name)
|
131
|
+
recent_job = most_recent_job
|
132
|
+
|
133
|
+
if recent_job&.class_name == job_class_name && recent_job&.args == job_args
|
134
|
+
recent_job
|
135
|
+
else
|
136
|
+
running_list = HistoryList.new(job_class_name, "running")
|
137
|
+
possible_jobs = running_list.jobs.select { |job| job.args == job_args }
|
138
|
+
|
139
|
+
possible_jobs.length == 1 ? possible_jobs.first : nil
|
140
|
+
end
|
141
|
+
end
|
106
142
|
end
|
107
143
|
end
|
108
144
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque-job_history
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RealNobody
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: resque
|