2016-07-28 54 views
1

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

有什么想法?

回答

1

使用delay通过PARAMS到要在后台运行的方法:

class EmailProcessor 

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

# Then somewhere down the line: 

EmailProcessor.delay.process(email) 
+1

这并没有解决问题,我仍然会试图通过“电子邮件”可变进延迟工作 – echan00

+0

你试过了吗? –