【问题标题】:Will delayed job run based on server time?延迟作业会根据服务器时间运行吗?
【发布时间】:2014-11-15 00:16:02
【问题描述】:

我在我的rails 应用程序中使用delayed_job。我想根据保存在 UTC 中的表列运行延迟作业。我的服务器设置在 EST 中。延迟作业将采用 UTC 还是 EST?

【问题讨论】:

    标签: ruby-on-rails ruby delayed-job


    【解决方案1】:

    如果您使用的是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 中使用,它查询数据库中的可用作业(从第 56 行开始)

    如果您不确定您的应用程序中设置了哪个时区,您可以使用 rails 控制台中的以下内容

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

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

    【讨论】:

      猜你喜欢
      • 2012-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 2016-03-29
      • 1970-01-01
      • 2012-10-29
      相关资源
      最近更新 更多