Module: Que::Scheduler::TimeZone

Defined in:
lib/que/scheduler/time_zone.rb

Constant Summary collapse

BOTH_CONFIG_AND_TIME_DOT_ZONE_SET =
"The que-scheduler config for time_zone has been set to a non-nil value, but\nit appears to also have been set on Time.zone (possibly by Rails). Both of these\ncannot be non-nil.\nYou should remove the time_zone config from the que-scheduler config block.\n".freeze
TIME_ZONE_COULD_NOT_BE_DETERMINED =
"It appears Time.zone is nil. This prevents proper functioning of que-scheduler.\n\nResolving this issue depends on your application setup.\n\n1) If you are using Rails, set the standard time_zone config\n   eg:\n   ```\n   # In application.rb\n   config.time_zone = \"Europe/London\"\n   ```\n\n2) If you are not using Rails, set your time zone in the que-scheduler config:\n   eg:\n   ```\n   Que::Scheduler.configure do |config|\n     config.time_zone = \"Europe/London\"\n   end\n   ```\n".freeze
TIME_ZONE_CONFIG_IS_NOT_VALID =
"The que-scheduler config for time_zone has been set to a non-nil value, but that value\ndoes not yield a real time zone when passed to ActiveSupport::TimeZone.new\n".freeze

Class Method Summary collapse

Class Method Details

.time_zoneObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/que/scheduler/time_zone.rb', line 38

def time_zone
  @time_zone ||=
    begin
      time_dot_zone = Time.zone
      if time_dot_zone.present?
        if Que::Scheduler.configuration.time_zone.present?
          raise BOTH_CONFIG_AND_TIME_DOT_ZONE_SET
        end

        time_dot_zone
      elsif Que::Scheduler.configuration.time_zone
        new_tz = ActiveSupport::TimeZone.new(Que::Scheduler.configuration.time_zone)
        raise TIME_ZONE_CONFIG_IS_NOT_VALID unless new_tz

        new_tz
      else
        raise TIME_ZONE_COULD_NOT_BE_DETERMINED
      end
    end
end