【问题标题】:Passing instance variables into delayed job将实例变量传递给延迟的作业
【发布时间】:2016-12-02 15:52:12
【问题描述】:

我正在尝试使用delayed_jobs(后台工作人员)来处理我收到的电子邮件。

class EmailProcessor

  def initialize(email)
    @raw_html = email.raw_html
    @subject = email.subject
  end

  def process
    do something with @raw_html & @subject
  end
  handle_asynchronously :process, :priority => 20

end

问题是我无法将实例变量(@raw_html 和@subject)传递给延迟的作业。延迟作业请求我将数据保存到模型中以便在后台任务中检索,但我希望让后台工作人员完成整个任务(包括保存记录)。

有什么想法吗?

【问题讨论】:

  • 我有工作人员为我将变量传递给我延迟的工作,你设法解决这个问题吗?

标签: ruby-on-rails delayed-job griddler


【解决方案1】:

使用delay 将参数传递给您要在后台运行的方法:

class EmailProcessor

  def self.process(email)
    # do something with the email
  end
end

# Then somewhere down the line:

EmailProcessor.delay.process(email)

【讨论】:

  • 这并不能解决问题,我仍然会尝试将“电子邮件”变量传递给延迟的作业
猜你喜欢
  • 2012-08-09
  • 2012-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多