2016-07-28 50 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

你試過了嗎? –