sidekiq-superworker 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sidekiq/superworker.rb +1 -0
- data/lib/sidekiq/superworker/processor.rb +1 -14
- data/lib/sidekiq/superworker/subjob_processor.rb +1 -10
- data/lib/sidekiq/superworker/superjob_processor.rb +59 -0
- data/lib/sidekiq/superworker/version.rb +1 -1
- data/lib/sidekiq/superworker/worker.rb +1 -18
- metadata +3 -2
data/lib/sidekiq/superworker.rb
CHANGED
@@ -17,20 +17,7 @@ module Sidekiq
|
|
17
17
|
raise "Job has nil jid: #{item}" if item['jid'].nil?
|
18
18
|
|
19
19
|
subjob = find_subjob_by_jid(item['jid'])
|
20
|
-
|
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
|
20
|
+
SuperjobProcessor.error(subjob.superjob_id, worker, item, exception)
|
34
21
|
end
|
35
22
|
|
36
23
|
protected
|
@@ -94,16 +94,7 @@ module Sidekiq
|
|
94
94
|
descendants_are_complete(parent)
|
95
95
|
# Otherwise, this is the final subjob of the superjob
|
96
96
|
else
|
97
|
-
|
98
|
-
if defined?(Sidekiq::Monitor)
|
99
|
-
job = Sidekiq::Monitor::Job.where(queue: :superworker, jid: subjob.superjob_id).first
|
100
|
-
if job
|
101
|
-
job.update_attributes(
|
102
|
-
status: 'complete',
|
103
|
-
finished_at: Time.now
|
104
|
-
)
|
105
|
-
end
|
106
|
-
end
|
97
|
+
SuperjobProcessor.complete(subjob.superjob_id)
|
107
98
|
end
|
108
99
|
end
|
109
100
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Superworker
|
3
|
+
class SuperjobProcessor
|
4
|
+
def self.queue_name
|
5
|
+
:superworker
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.create(superjob_id, superworker_class_name, args, subjobs)
|
9
|
+
# If sidekiq_monitor is being used, create a Sidekiq::Monitor::Job for the superjob
|
10
|
+
if defined?(Sidekiq::Monitor)
|
11
|
+
now = Time.now
|
12
|
+
Sidekiq::Monitor::Job.create(
|
13
|
+
jid: superjob_id,
|
14
|
+
queue: queue_name,
|
15
|
+
class_name: superworker_class_name,
|
16
|
+
args: args,
|
17
|
+
enqueued_at: now,
|
18
|
+
started_at: now,
|
19
|
+
status: 'running'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Enqueue the first root-level subjob
|
24
|
+
first_subjob = subjobs.select{ |subjob| subjob.parent_id.nil? }.first
|
25
|
+
SubjobProcessor.enqueue(first_subjob)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.complete(superjob_id)
|
29
|
+
# Set the superjob Sidekiq::Monitor::Job as being complete
|
30
|
+
if defined?(Sidekiq::Monitor)
|
31
|
+
job = Sidekiq::Monitor::Job.where(queue: queue_name, jid: superjob_id).first
|
32
|
+
if job
|
33
|
+
job.update_attributes(
|
34
|
+
status: 'complete',
|
35
|
+
finished_at: Time.now
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.error(superjob_id, worker, item, exception)
|
42
|
+
if defined?(Sidekiq::Monitor)
|
43
|
+
job = Sidekiq::Monitor::Job.where(queue: queue_name, jid: superjob_id).first
|
44
|
+
if job
|
45
|
+
result = {
|
46
|
+
message: "#{exception.message} (thrown in #{worker.class}, JID: #{item['jid']})",
|
47
|
+
backtrace: exception.backtrace
|
48
|
+
}
|
49
|
+
job.update_attributes(
|
50
|
+
finished_at: DateTime.now,
|
51
|
+
status: 'failed',
|
52
|
+
result: result
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -26,24 +26,7 @@ module Sidekiq
|
|
26
26
|
def perform_async(*arg_values)
|
27
27
|
@args = Hash[@arg_keys.zip(arg_values)]
|
28
28
|
subjobs = create_subjobs
|
29
|
-
|
30
|
-
# Create a Sidekiq::Monitor::Job for the superjob
|
31
|
-
if defined?(Sidekiq::Monitor)
|
32
|
-
now = Time.now
|
33
|
-
Sidekiq::Monitor::Job.create(
|
34
|
-
args: arg_values,
|
35
|
-
class_name: @class_name,
|
36
|
-
enqueued_at: now,
|
37
|
-
jid: @superjob_id,
|
38
|
-
queue: :superworker,
|
39
|
-
started_at: now,
|
40
|
-
status: 'running'
|
41
|
-
)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Enqueue the first root-level subjob
|
45
|
-
first_subjob = subjobs.select{ |subjob| subjob.parent_id.nil? }.first
|
46
|
-
SubjobProcessor.enqueue(first_subjob)
|
29
|
+
SuperjobProcessor.create(@superjob_id, @class_name, arg_values, subjobs)
|
47
30
|
end
|
48
31
|
|
49
32
|
protected
|
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.3
|
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-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/sidekiq/superworker/processor.rb
|
107
107
|
- lib/sidekiq/superworker/server/middleware.rb
|
108
108
|
- lib/sidekiq/superworker/subjob_processor.rb
|
109
|
+
- lib/sidekiq/superworker/superjob_processor.rb
|
109
110
|
- lib/sidekiq/superworker/version.rb
|
110
111
|
- lib/sidekiq/superworker/worker.rb
|
111
112
|
- lib/sidekiq/superworker.rb
|