jbmyid
jbmyid

Reputation: 2015

Pass proc/lambda in resque jobs

I am using resque gem for background tasks. I want to pass proc as an argument to the worker. Is there a way to do that? eg:

Resque.enqueue_in(3.hours, ExecuteAfterIntervalWorker, self.class.name, self.id, method_name, if: Proc.new{|e| e.enabled? })

Upvotes: 0

Views: 449

Answers (2)

Omar Qureshi
Omar Qureshi

Reputation: 9093

Why not just create a wrapping job that may or may not run the proper job for you?

class ExecuteAfterIntervalWorkerIfEnabled
  def self.perform(...)
    obj = Object.find(id)
    ExecuteAfterIntervalWorker.perform(...) if obj.enabled?
  end
end

Upvotes: 0

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230521

Things you pass to resque, they must be serializable to json. And procs aren't serializable to json. So, no luck for you here.

Do you really need that level of dynamism, though?

Upvotes: 1

Related Questions