sidekiq-superworker 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,8 @@ module Sidekiq
5
5
  @dsl_evaluator = DSLEvaluator.new
6
6
  @dsl_hash = DSLHash.new
7
7
  @record_id = 0
8
- block_to_nested_hash(block)
8
+ nested_hash = block_to_nested_hash(block)
9
+ @dsl_hash.rewrite_ids_of_nested_hash(nested_hash, 0)
9
10
  end
10
11
 
11
12
  def self.block_to_nested_hash(block)
@@ -17,6 +18,7 @@ module Sidekiq
17
18
  while (method_result = fiber.resume)
18
19
  method, args, block = method_result
19
20
  @record_id += 1
21
+ method_record_id = @record_id
20
22
  if block
21
23
  if method == :batch
22
24
  nested_hash[@record_id] = { subworker_class: method, arg_keys: args, children: block_to_nested_hash(block) }
@@ -32,14 +34,29 @@ module Sidekiq
32
34
  unless [:parallel, :batch].include?(method)
33
35
  subworker_class = method.to_s.constantize
34
36
  if subworker_class.respond_to?(:is_a_superworker?) && subworker_class.is_a_superworker?
35
- parent_record_id = @record_id
36
- nested_hash[parent_record_id][:children] = @dsl_hash.rewrite_ids_of_nested_hash(subworker_class.nested_hash, @record_id)
37
+ children = @dsl_hash.rewrite_ids_of_nested_hash(subworker_class.nested_hash, @record_id)
38
+ set_children_for_record_id(nested_hash, method_record_id, children)
37
39
  @record_id = @dsl_hash.record_id
38
40
  end
39
41
  end
40
42
  end
41
43
  nested_hash
42
44
  end
45
+
46
+ def self.set_children_for_record_id(nested_hash, parent_record_id, children)
47
+ nested_hash.each do |record_id, value|
48
+ if record_id == parent_record_id
49
+ if nested_hash[record_id][:children].present?
50
+ nested_hash[record_id][:children] = nested_hash[record_id][:children].reverse_merge(children)
51
+ else
52
+ nested_hash[record_id][:children] = children
53
+ end
54
+ end
55
+ if value[:children].present?
56
+ set_children_for_record_id(value[:children], parent_record_id, children)
57
+ end
58
+ end
59
+ end
43
60
  end
44
61
  end
45
62
  end
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Superworker
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
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.1.0
4
+ version: 0.1.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-09-05 00:00:00.000000000 Z
12
+ date: 2013-09-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq