簡體   English   中英

Rails 中 DelayedJob 的輔助類

[英]Helper Classes for DelayedJob in Rails

為了按計划啟動delayed_job,您需要有一個具有delayed_job 可以調用的perform方法的輔助類。 這些需要在調用任何使用它們來創建預定延遲作業的類之前定義。 都非常短,在我的情況下很多。 例如:

class AccountUpdateJob < Struct.new(:account_id)
  def perform
    acct = Account.find(account_id)
    acct.api_update
  end
end   

我在初始化文件夾中名為“dj_helper_classes”的文件中執行此操作。 這是正確的做法嗎?

我將我的保存在 lib/jobs 中,每個 class 一個文件。 因此,您的示例將在 lib/jobs/account_update_job.rb

module Jobs
    class AccountUpdateJob < Struct.new(:account_id)
        def perform
          acct = Account.find(account_id)
          acct.api_update
        end
    end
end   

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM