【发布时间】:2023-03-09 03:47:01
【问题描述】:
我正在使用 Delayed::Job 从 Rails 应用程序发送短信。我在 Gemfile 中包含如下 gem。
gem 'delayed_job', "~> 4.1.1"
我还添加了一个自定义延迟作业作为
class SendSmsJob < Struct.new(:person_id, :content)
include DelayedAirbrakeNotification
def perform
person = Person.find(person_id)
phone = person.phone_number
....
....
....
end
end
我正在从控制器触发这项工作,如下所示,
Delayed::Job.enqueue(SendSmsJob.new(@person.id, "Test message"))
但是当我尝试在perform 方法下使用person_id 和content 的值时,我分别得到nil 和""。
我对其他工作采用相同的方法,并且这些工作完美无缺,
我不知道我是否在这里遗漏了什么。
任何建议将不胜感激。
【问题讨论】:
-
您是否尝试传递不带 id 的 person 对象?像这样Delayed::Job.enqueue(SendSmsJob.new(@person, "Test message")),然后直接调用@person.phone_number等
-
@AlexanderLuna 是的,我试过了,同样的问题。
标签: ruby-on-rails ruby ruby-on-rails-4 delayed-job