【问题标题】:Delayed_job not saving in databaseDelayed_job 未保存在数据库中
【发布时间】: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 &lt;command&gt; &lt;options&gt; -- &lt;application options&gt;
  • NickM => handle_asynchronously :push, :run_at =&gt; Proc.new {|i| i.when_to_run } 和 push 方法就在它的正上方。
  • 你开始延迟工作了吗? script/delayed_job status 的输出?

标签: ruby-on-rails ruby ruby-on-rails-4 activerecord delayed-job


【解决方案1】:

我意识到我正在开发的应用程序已经出于其他目的实施了 Sidekiq,并且看起来这两个应用程序受到了干扰。当 Sidekiq 界面打开时,我可以看到那里的作业,即使它们没有显示在延迟的作业查询中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-02
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 1970-01-01
    相关资源
    最近更新 更多