Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix batch pass wrong arguments #49

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/sidekiq-superworker.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require 'active_model'
require 'active_support/all'
require 'sidekiq/superworker'
require 'sidekiq/superworker'
15 changes: 6 additions & 9 deletions lib/sidekiq/superworker/dsl_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def to_records

def nested_hash_to_records(nested_hash, options={})
return @records if nested_hash.blank?

defaults = {
parent_id: nil,
scoped_args: nil # Args that are scoped to this subset of the nested hash (necessary for batch hashes)
Expand All @@ -44,18 +43,17 @@ def nested_hash_to_records(nested_hash, options={})
arg_key
end
end

@records[id] = {
subjob_id: id,
subworker_class: value[:subworker_class].to_s,
arg_keys: value[:arg_keys],
arg_values: arg_values,
parent_id: parent_id
}

if value[:subworker_class] == :batch
@arg_keys_to_arg_keys ||= Hash[@args.keys.map { |key| [key, key] }]
batch_keys_to_iteration_keys = @arg_keys_to_arg_keys.merge(arg_values[0])
@records[id][:children_ids] = children_ids_for_batch(value[:children], batch_keys_to_iteration_keys)
@records[id][:children_ids] = children_ids_for_batch(value[:children], arg_values[0])
end

@records[last_id][:next_id] = id if @records[last_id]
Expand Down Expand Up @@ -84,7 +82,6 @@ def children_ids_for_batch(subjobs, batch_keys_to_iteration_keys)
arg_key = iteration_keys[arg_index]
iteration_args[arg_key] = arg_value
end

batch_child_id = @record_id
batch_child = {
subjob_id: batch_child_id,
Expand All @@ -95,7 +92,6 @@ def children_ids_for_batch(subjobs, batch_keys_to_iteration_keys)
children_ids: []
}
@records[batch_child_id] = batch_child

@record_id += 1
last_subjob_id = nil
subjobs.values.each_with_index do |subjob, index|
Expand All @@ -115,7 +111,6 @@ def children_ids_for_batch(subjobs, batch_keys_to_iteration_keys)

children_ids << batch_child_id
end

children_ids
end

Expand Down Expand Up @@ -152,7 +147,9 @@ def batch_values_to_batch_arrays(values)
array
end
first_array = arrays.shift
first_array.zip(*arrays)
array_values = first_array.zip(*arrays)
array_values = [[nil]] if array_values == []
array_values
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq/superworker/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Sidekiq
module Superworker
VERSION = '1.2.0'
VERSION = '1.2.1'
end
end
72 changes: 36 additions & 36 deletions spec/dsl_hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
Worker2 :first_argument, :second_argument
end
end

hash = Sidekiq::Superworker::DSLParser.new.parse(block)
args = {
first_arguments: [10, 11, 12],
Expand Down Expand Up @@ -230,7 +230,7 @@
BatchNestedSuperworker :first_argument
end
end

hash = Sidekiq::Superworker::DSLParser.new.parse(block)

args = {
Expand Down Expand Up @@ -316,7 +316,7 @@
Worker1 :first_argument
end
end

hash = Sidekiq::Superworker::DSLParser.new.parse(block)

args = {
Expand Down Expand Up @@ -420,45 +420,45 @@
dsl_hash = described_class.new(hash, args)
dsl_hash.to_records.should ==
{1=>
{:subjob_id=>1,
{ :subjob_id=>1,
:subworker_class=>"Worker1",
:arg_keys=>[:first_argument],
:arg_values=>[20],
:parent_id=>nil,
:arg_values=>[20], :parent_id=>nil,
:children_ids=>[2]},
2=>
{:subjob_id=>2,
:subworker_class=>"batch",
:arg_keys=>[{:second_arguments=>:second_argument}],
:arg_values=>[{:second_arguments=>:second_argument}],
:parent_id=>1,
:children_ids=>[3, 5]},
3=>
{:subjob_id=>3,
:subworker_class=>"batch_child",
:arg_keys=>[:first_argument, :second_argument],
:arg_values=>[20, 10],
:parent_id=>2,
:children_ids => [4]},
4=>
{:subworker_class=>:Worker2,
:arg_keys=>[:first_argument, :second_argument],
:subjob_id=>4,
:parent_id=>3,
:arg_values=>[20, 10]},
5=>
{:subjob_id=>5,
:subworker_class=>"batch_child",
:arg_keys=>[:first_argument, :second_argument],
:arg_values=>[20, 11],
:parent_id=>2,
:children_ids => [6]},
6=>
{:subworker_class=>:Worker2,
2=>
{ :subjob_id=>2,
:subworker_class=>"batch",
:arg_keys=>[{:second_arguments=>:second_argument}],
:arg_values=>[{:second_arguments=>:second_argument}],
:parent_id=>1, :children_ids=>[3, 5]},
3=>
{ :subjob_id=>3,
:subworker_class=>"batch_child",
:arg_keys=>[:second_argument],
:arg_values=>[10],
:parent_id=>2,
:children_ids=>[4]},
4=>
{ :subworker_class=>:Worker2,
:arg_keys=>[:first_argument,:second_argument],
:subjob_id=>4,
:parent_id=>3,
:arg_values=>[10]},
5=>
{ :subjob_id=>5,
:subworker_class=>"batch_child",
:arg_keys=>[:second_argument],
:arg_values=>[11],
:parent_id=>2,
:children_ids=>[6]},
6=>
{ :subworker_class=>:Worker2,
:arg_keys=>[:first_argument, :second_argument],
:subjob_id=>6,
:parent_id=>5,
:arg_values=>[20, 11]}}
:arg_values=>[11]
}
}
end
end
end
Expand Down