【发布时间】:2015-03-18 19:20:28
【问题描述】:
我正在使用 Ruby on Rails 并尝试通过使用延迟作业来添加调度通知推送的功能。我根据文档实现了 gem 并通过运行 rake jobs:work 启动了工作人员,但尽管我尽了最大努力,但没有保存任何工作。我在控制台中尝试了Delayed::Job.all,但无论我做什么,它都会返回一个空数组。
我的模特:
class MessageSocialAccount < ActiveRecord::Base
attr_accessible :social_account_id, :message_id, :read_time, :push_notification
attr_reader :when_to_run
belongs_to :message
belongs_to :social_account
def when_to_run
message.deliver_at || Time.now
end
def push
social_account.send_push(msg_sca.message)
update_attributes!(:push_notification => true)
end
handle_asynchronously :push, :run_at => Proc.new {|i| i.when_to_run }
end
我在日志中看不到delayed_job.log,development.log也不包含任何线索。
您知道问题可能是什么吗?谢谢
*编辑 我从中调用它的模型: 消息.rb
class Message < ActiveRecord::Base
def send_push_to_all(delivery_time=nil)
self.message_social_accounts.map{|msg_sca| msg_sca.push} unless self.reward.status=="qa"
self.update_attributes!(:sent_at => Time.now)
end
end
调用来自控制器:
msg.send_push_to_all(msg.deliver_at)
【问题讨论】:
-
拨打
bin/delayed_job会发生什么? -
你在哪里调用push方法?
-
Magnuss 我得到 ``` 错误:没有给出命令```
Usage: delayed_job <command> <options> -- <application options> -
NickM =>
handle_asynchronously :push, :run_at => Proc.new {|i| i.when_to_run }和 push 方法就在它的正上方。 -
你开始延迟工作了吗?
script/delayed_job status的输出?
标签: ruby-on-rails ruby ruby-on-rails-4 activerecord delayed-job