I'm a bit at a loss here.
I'm simply trying to delay a checkin, for instance, at a user defined time. I'd like to make it as simple as possible.
EDIT: solved, see below.
class MyController < ApplicationController
def new_checkin
# default venue is "SubMate"
@venue_id = params[:venue_id] || "4c2c3acd8abca59355760120"
@time = params[:time]
@checkin = Delayed::Job.enqueue(self.perform_checkin, :run_at => @time.minutes.from_now)
end
def perform_checkin
foursquare.checkins.add(:venueId => @venue_id, :broadcast => "private")
end
The result is strange : the delayed_job is save, the action is performed (without the requested @time delay), and i still get an error:
ArgumentError in MyController#new_checkin
Cannot enqueue items which do not respond to perform
What am I missing? How can I perform this delayed job, with the user requested delay?
Thank you!
UPDATE
Thanks to @Roman below, didn't know you could pass arguments to delay:
def new_checkin
@venue_id = params[:venue_id]
@time = params[:time]
@checkin = self.perform_checkin
end
def perform_checkin
foursquare.checkins.delay({:run_at => @time.minutes.from_now}).add(:venueId => @venue_id, :broadcast => "private")
end
If you want to enqueue it this way, then as the error suggests, the enqueued object should respond to :perform. Check this http://asciicasts.com/episodes/171-delayed-job You can also use :handle_asynchronously or .delay.method. Check this: https://github.com/collectiveidea/delayed_job
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With