ruby on rails - conflict delayed_job / sidekiq -
i have app both sidekiq , delayed job gems installed. when trigger handle_asynchronously in active record models appear handled sidekiq while trigger delayed_job.
is there way desactivate sidekiq specific model?
as mention in comment in order working have redefine/basically monkey patch handle_asynchronously method
anywhere (but make sure loaded )
in config/initializers/patch.rb code
module patch def handle_asynchronously(method, opts = {}) aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1 with_method, without_method = "#{aliased_method}_with_delay#{punctuation}", "#{aliased_method}_without_delay#{punctuation}" define_method(with_method) |*args| curr_opts = opts.clone curr_opts.each_key |key| if (val = curr_opts[key]).is_a?(proc) curr_opts[key] = if val.arity == 1 val.call(self) else val.call end end end ## replace other syntax # delay(curr_opts).__send__(without_method, *args) __delay__(curr_opts).__send__(without_method, *args) end alias_method_chain method, :delay end end module.send(:include,patch) and believe rest follow way should :)
reason:
delayed::job include delay method on object , sidekiq include delay method on activerecord hence when class try invoke delay ancestors class (including eigen class) , find method define or included in activerecord::base class (which sidekiq delay)
why __delay__ work because alias define copy of existing method delay method of delayedjob , hence when invoke __delay__ method invoke delay method define delayedjob include object
note:
although solution bit patch works . keeping in mind every direct .delay methid invocation invoking delay method of sidekiq , not delayedjob invoke delayedjob delay method has call way __delay__
suggestion :
monkey patching bad practice on personal note rather not use 2 entirely different background processing library single application achieve same task. if task process thing in background why cant done single library either delayed_job or sidekiq (why required both of them )
so point , thing make background processing ease respect future sincerely advice take 1 of 2 library background processing , feel valid answer question instead of monkey patching doing other crazy stuff
hope help
Comments
Post a Comment