gpt4 book ai didi

ruby-on-rails - 将实例变量传递给延迟作业

转载 作者:行者123 更新时间:2023-12-03 08:36:24 25 4
gpt4 key购买 nike

我正在尝试使用 delay_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)传递给延迟的作业。延迟作业要求我将数据保存到模型中以在后台任务中检索,但我更希望让后台工作人员完成整个任务(包括保存记录)。

有什么想法吗?

最佳答案

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

class EmailProcessor

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

# Then somewhere down the line:

EmailProcessor.delay.process(email)

关于ruby-on-rails - 将实例变量传递给延迟作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38633240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com