非持续记录和延迟工作

时间:2015-06-08 08:19:22

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

有没有办法在延迟工作中添加非持久性记录?我最近更新了我的Rails版本,但现在我无法在延迟工作中添加非持久性记录。

这是我的班级:

class InfoPackDownload

  include ActiveAttr::Model
  include ::NewRelic::Agent::MethodTracer

  attribute :course_id
  attribute :first_name
  attribute :last_name
  attribute :email
  attribute :telephone
  attribute :receive_newsletter, type: Boolean
  attribute :filename
  attribute :course_code
  attribute :programme_instance_code
  attribute :presentation
  attribute :title

  validates_presence_of :first_name, :last_name
  validates :email, presence: true, email: true

  def send_interaction
    body_params = create_request_body
    request = build_request body_params
    send_request request
  end
end

我正在尝试将以下方法添加到延迟作业中:

@info_pack_download.delay(queue: 'info_pack_download').send_interaction

但是当我调用此方法时,会引发错误,以便将非持久性记录添加到延迟作业。

有人可以就这个问题提出一些建议吗?

1 个答案:

答案 0 :(得分:0)

延迟作业需要将作业的参数存储到数据库,以便稍后在作业调度后检索它们。如果它是一个简单的ruby对象,它可以将它序列化为字符串(to_json),并存储它。如果它是数据库模型,则存储ID和类名。

当作业计划运行时,它需要将参数拉出数据库。对于简单模型,它可以反序列化字符串(JSON.parse),对于数据库模型,它可以使用类名和ID从数据库加载模型。你没有提供办法。

相关问题