簡體   English   中英

是否會根據服務器時間推遲工作?

[英]Will delayed job run based on server time?

我在rails應用程序中使用delayed_job。 我想根據以UTC格式保存的表列運行delayed_job。 我的服務器設置在EST中。 延遲工作需要UTC還是EST?

如果您使用的是active_record_delayed_job則將使用active_record_delayed_job中設置的application.rb程序時區。

以下內容來自delayed_job來源( https://github.com/collectiveidea/delayed_job_active_record/blob/master/lib/delayed/backend/active_record.rb#L97

    # Get the current time (GMT or local depending on DB)
    # Note: This does not ping the DB to get the time, so all your clients
    # must have syncronized clocks.
    def self.db_time_now
      if Time.zone
        Time.zone.now
      elsif ::ActiveRecord::Base.default_timezone == :utc
        Time.now.utc
      else
        Time.now
      end
    end

這在reserve_with_scope中使用,它向DB查詢可用的作業(從第56行開始)

如果您不確定應用程序中設置了哪個時區,則可以使用rails控制台中的以下內容

2.1.4 :005 > Rails.application.config.time_zone
 => "Helsinki"

要么

2.1.4 :007 > Time.zone.name
 => "Helsinki" 

暫無
暫無

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

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