sidekiq-superworker 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,13 +29,29 @@ end
29
29
 
30
30
  Superworker = Sidekiq::Superworker::Worker unless Object.const_defined?('Superworker')
31
31
 
32
- # If sidekiq_monitor is being used, customize how superjobs are monitored
33
32
  if defined?(Sidekiq::Monitor)
33
+
34
34
  # Make Cleaner ignore superjobs, as they don't exist in Redis and thus won't be synced with Sidekiq::Monitor::Job
35
35
  Sidekiq::Monitor::Cleaner.add_ignored_queue(Sidekiq::Superworker::SuperjobProcessor.queue_name) if defined?(Sidekiq::Monitor)
36
36
 
37
37
  # Add a custom view that shows the subjobs for a superjob
38
- Sidekiq::Monitor::CustomViews.add 'Subjobs', "#{directory}/../../app/views/sidekiq/superworker/subjobs" do |job|
38
+ custom_views_directory = "#{directory}/../../app/views/sidekiq/superworker/subjobs"
39
+ Sidekiq::Monitor::CustomViews.add 'Subjobs', custom_views_directory do |job|
39
40
  job.queue == Sidekiq::Superworker::SuperjobProcessor.queue_name.to_s
40
41
  end
42
+
43
+ # Add a "superjob:{id}" search filter
44
+ Sidekiq::Monitor::JobsDatatable.add_search_filter({
45
+ pattern: /^superjob:([\d]+)$/,
46
+ filter: lambda do |search_term, records|
47
+ superjob_id = search_term[/^superjob:([\d]+)$/, 1]
48
+ superjob = Sidekiq::Monitor::Job.find_by_id(superjob_id)
49
+ # Return empty set
50
+ return records.where(id: nil) unless superjob
51
+ superjob_jid = superjob.jid
52
+ subjob_jids = Sidekiq::Superworker::Subjob.where(superjob_id: superjob_jid).map(&:jid).compact
53
+ records.where(jid: subjob_jids + [superjob_jid])
54
+ end
55
+ })
56
+
41
57
  end
@@ -19,7 +19,7 @@ module Sidekiq
19
19
 
20
20
  Superworker.debug "JID ##{item['jid']}: Error thrown"
21
21
  subjob = find_subjob_by_jid(item['jid'])
22
- SuperjobProcessor.error(subjob.superjob_id, worker, item, exception) if subjob
22
+ SubjobProcessor.error(subjob, worker, item, exception) if subjob
23
23
  end
24
24
 
25
25
  protected
@@ -8,12 +8,13 @@ module Sidekiq
8
8
 
9
9
  def call(worker, item, queue)
10
10
  begin
11
- yield
11
+ return_value = yield
12
12
  rescue Exception => exception
13
13
  @processor.error(worker, item, queue, exception)
14
14
  raise exception
15
15
  end
16
16
  @processor.complete(item)
17
+ return_value
17
18
  end
18
19
  end
19
20
  end
@@ -82,6 +82,12 @@ module Sidekiq
82
82
  end
83
83
  end
84
84
 
85
+ def self.error(subjob, worker, item, exception)
86
+ Superworker.debug "#{subjob.to_info}: Error"
87
+ subjob.update_attribute(:status, 'failed')
88
+ SuperjobProcessor.error(subjob.superjob_id, worker, item, exception)
89
+ end
90
+
85
91
  def self.descendants_are_complete(subjob)
86
92
  Superworker.debug "#{subjob.to_info}: Descendants are complete"
87
93
  subjob.update_attribute(:descendants_are_complete, true)
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Superworker
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  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.6
4
+ version: 0.0.7
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-07-10 00:00:00.000000000 Z
12
+ date: 2013-07-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq