lib/resque/scheduler/configuration.rb in resque-scheduler-4.5.0 vs lib/resque/scheduler/configuration.rb in resque-scheduler-4.6.0

- old
+ new

@@ -6,68 +6,91 @@ # Allows for block-style configuration def configure yield self end + attr_writer :environment + def environment + @environment ||= ENV + end + # Used in `#load_schedule_job` attr_writer :env def env return @env if @env @env ||= Rails.env if defined?(Rails) && Rails.respond_to?(:env) - @env ||= ENV['RAILS_ENV'] + @env ||= environment['RAILS_ENV'] @env end # If true, logs more stuff... attr_writer :verbose def verbose - @verbose ||= !!ENV['VERBOSE'] + @verbose ||= to_bool(environment['VERBOSE']) end # If set, produces no output attr_writer :quiet def quiet - @quiet ||= !!ENV['QUIET'] + @quiet ||= to_bool(environment['QUIET']) end # If set, will write messages to the file attr_writer :logfile def logfile - @logfile ||= ENV['LOGFILE'] + @logfile ||= environment['LOGFILE'] end # Sets whether to log in 'text' or 'json' attr_writer :logformat def logformat - @logformat ||= ENV['LOGFORMAT'] + @logformat ||= environment['LOGFORMAT'] end # If set, will try to update the schedule in the loop attr_writer :dynamic def dynamic - @dynamic ||= !!ENV['DYNAMIC_SCHEDULE'] + @dynamic ||= to_bool(environment['DYNAMIC_SCHEDULE']) end # If set, will append the app name to procline attr_writer :app_name def app_name - @app_name ||= ENV['APP_NAME'] + @app_name ||= environment['APP_NAME'] end # Amount of time in seconds to sleep between polls of the delayed # queue. Defaults to 5 attr_writer :poll_sleep_amount def poll_sleep_amount @poll_sleep_amount ||= - Float(ENV.fetch('RESQUE_SCHEDULER_INTERVAL', '5')) + Float(environment.fetch('RESQUE_SCHEDULER_INTERVAL', '5')) + end + + private + + # Copied from https://github.com/rails/rails/blob/main/activemodel/lib/active_model/type/boolean.rb#L17 + TRUE_VALUES = [ + true, 1, + '1', :'1', + 't', :t, + 'T', :T, + 'true', :true, + 'TRUE', :TRUE, + 'on', :on, + 'ON', :ON + ].to_set.freeze + + def to_bool(value) + TRUE_VALUES.include?(value) end end end end