我在这里有点不知所措。
我只是试图在用户定义的时间延迟签入。我想尽量简单。
编辑:已解决,请参阅下文。
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
结果很奇怪:delayed_job是保存,执行操作(没有请求的@time延迟),我仍然收到错误:
ArgumentError in MyController#new_checkin
Cannot enqueue items which do not respond to perform
我错过了什么?如何以用户请求的延迟执行此延迟作业?
谢谢!
更新
感谢下面的@Roman,不知道你可以传递参数来延迟:
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
答案 0 :(得分:8)
如果你想以这种方式排队,那么正如错误所暗示的那样,排队的对象应该响应:perform。检查一下http://asciicasts.com/episodes/171-delayed-job 您还可以使用:handle_asynchronously或.delay.method。检查一下:https://github.com/collectiveidea/delayed_job