Search code examples
ruby-on-railsrubysidekiq

Is it possible to send Blocks or Procs as arguments to Sidekiq?


I have a standard system for performing calculations on varied datasets. What would be great is I could just pass those calculations as a Proc to the perform method. Here's what I want to accomplish:

class Calculator
    include Sidekiq::Worker

    def perform rails_model , rails_model_id
         obj = Kernel.const_get( rails_model ).find( rails_model_id )
         yield( obj )
    end
end

Calculator.perform_asyc( "User" , 123 , { |u| u.do_something } )

Is this sort of thing possible or is it bad practice? I know that it's bad practice to send objects directly, so I'm assuming that sending blocks is also a bad idea?


Solution

  • This is not possible. There is no serialization format for code in Ruby, only for data.