Skip to content

Commit

Permalink
fix: when defining custom task on index level, keep the ones from global
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosgz committed Sep 17, 2024
1 parent cfde8c5 commit 3ffa7e3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GIT
PATH
remote: .
specs:
esse-async_indexing (0.1.0.rc3)
esse-async_indexing (0.1.0.rc4)
background_job
esse (>= 0.4.0.rc1)
multi_json
Expand Down
6 changes: 6 additions & 0 deletions lib/esse/async_indexing/tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def fetch(name)
end
alias_method :[], :fetch

def dup
new_task = self.class.new
new_task.instance_variable_set(:@tasks, @tasks.dup)
new_task
end

private

def validate!(names, block)
Expand Down
2 changes: 1 addition & 1 deletion lib/esse/async_indexing/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Esse
module AsyncIndexing
VERSION = "0.1.0.rc3"
VERSION = "0.1.0.rc4"
end
end
2 changes: 1 addition & 1 deletion lib/esse/plugins/async_indexing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def implement_batch_ids?
# MyCustomJob.perform_later(repo.index.name, [id], **kwargs)
# end
def async_indexing_job(*operations, &block)
definer = @async_indexing_tasks || Esse::AsyncIndexing::Tasks.new
definer = @async_indexing_tasks || Esse.config.async_indexing.tasks.dup
definer.define(*operations, &block)
@async_indexing_tasks = definer
end
Expand Down
9 changes: 9 additions & 0 deletions spec/esse/async_indexing/tasks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,13 @@
it_behaves_like "a task fetch for", :delete
it_behaves_like "a task fetch for", :update_lazy_attribute
end

describe "#dup" do
it "duplicates the tasks" do
import_task = ->(**) {}
tasks.define(:import, &import_task)
new_tasks = tasks.dup
expect(new_tasks[:import]).to eq(import_task)
end
end
end

0 comments on commit 3ffa7e3

Please sign in to comment.