sidekiq-superworker 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -13,18 +13,44 @@ module Sidekiq
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
def error(worker, item, queue, exception)
|
17
|
+
raise "Job has nil jid: #{item}" if item['jid'].nil?
|
18
|
+
|
19
|
+
subjob = find_subjob_by_jid(item['jid'])
|
20
|
+
if defined?(Sidekiq::Monitor)
|
21
|
+
job = Sidekiq::Monitor::Job.where(queue: :superworker, jid: subjob.superjob_id).first
|
22
|
+
if job
|
23
|
+
result = {
|
24
|
+
message: "#{exception.message} (thrown in #{worker.class}, JID: #{item['jid']})",
|
25
|
+
backtrace: exception.backtrace
|
26
|
+
}
|
27
|
+
job.update_attributes(
|
28
|
+
finished_at: DateTime.now,
|
29
|
+
status: 'failed',
|
30
|
+
result: result
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
16
36
|
protected
|
17
37
|
|
18
38
|
def complete_item(item)
|
19
39
|
raise "Job has nil jid: #{item}" if item['jid'].nil?
|
40
|
+
|
41
|
+
subjob = find_subjob_by_jid(item['jid'])
|
42
|
+
SubjobProcessor.complete(subjob) if subjob
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_subjob_by_jid(jid)
|
20
46
|
# The job may complete before the Subjob record is created; in case that happens,
|
21
47
|
# we need to sleep briefly and requery.
|
22
48
|
tries = 3
|
23
|
-
while !(subjob = Subjob.find_by_jid(
|
49
|
+
while !(subjob = Subjob.find_by_jid(jid)) && tries > 0
|
24
50
|
sleep 1
|
25
51
|
tries -= 1
|
26
52
|
end
|
27
|
-
|
53
|
+
subjob
|
28
54
|
end
|
29
55
|
end
|
30
56
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-superworker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-06-
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|