searchkick
searchkick copied to clipboard
Add parent_job attr to change inheritance af jobs
Hi,
In order to add some callbacks to Searchkick jobs or use new features from ActiveJob, it could be nice to have a config option to change the default inheritance.
This is also an opportunity to thank you for this awesome gem! Kevyn
Hey @kevynlebouille, thanks for the PR (and sorry for the long delay)! Can you explain more about the use case?
Hi @ankane , with a multi-tenant context, I need to set a Current attribute while indexing.
Long story short, below my code sample from my initializer:
module Searchkick
module TenantJobDecorator
def self.prepended(base)
base.attr_accessor :current_project
base.around_perform do |job, block|
Current.set(project: job.current_project || Current.project, &block)
end
end
def serialize
super.merge('project_id' => Current.project&.id)
end
def deserialize(job_data)
super
self.current_project = Project.find_by(id: job_data['project_id'])
end
end
end
Searchkick::BulkReindexJob.prepend Searchkick::TenantJobDecorator
Searchkick::ProcessBatchJob.prepend Searchkick::TenantJobDecorator
Searchkick::ProcessQueueJob.prepend Searchkick::TenantJobDecorator
Searchkick::ReindexV2Job.prepend Searchkick::TenantJobDecorator
Cheers, Kevyn
I also find it very useful when using sidekiq
with sidekiq_options
that are not defined in ActiveJob
This would be very useful for us as well 👍
Our use case is that we have statistics tracking and retry logic defined in our ApplicationJob. Currently we have to open all the job classes and monkey patch them with the same logic (and keep track of changes regarding new jobs in this project)
Hi @ankane , it's the come back of my PR (freshly rebased). If you don't want to merged that PR, could you explain quickly why ? Thx