Class: Schked::Config
- Inherits:
-
Object
- Object
- Schked::Config
- Defined in:
- lib/schked/config.rb
Constant Summary collapse
- VALID_JOB_RUN_STORES =
%i[redis database].freeze
Instance Attribute Summary collapse
-
#database_connection ⇒ Object
Returns the value of attribute database_connection.
-
#do_not_load_root_schedule ⇒ Object
writeonly
Sets the attribute do_not_load_root_schedule.
-
#job_run_store ⇒ Object
Returns the value of attribute job_run_store.
- #logger ⇒ Object
- #max_skew ⇒ Object
- #redis ⇒ Object
-
#standalone ⇒ Object
writeonly
Sets the attribute standalone.
Instance Method Summary collapse
- #dedup_enabled? ⇒ Boolean
- #do_not_load_root_schedule? ⇒ Boolean
- #fire_around_callback(name, job, calls = , &block) ⇒ Object
- #fire_callback(name, *args) ⇒ Object
- #liveness_probe ⇒ Object
- #liveness_probe=(value) ⇒ Object
- #logger? ⇒ Boolean
- #paths ⇒ Object
- #redis_servers=(val) ⇒ Object
- #register_callback(name, &block) ⇒ Object
- #standalone? ⇒ Boolean
-
#validate! ⇒ Object
Validates all configuration options.
Instance Attribute Details
#database_connection ⇒ Object
Returns the value of attribute database_connection.
95 96 97 |
# File 'lib/schked/config.rb', line 95 def database_connection @database_connection end |
#do_not_load_root_schedule=(value) ⇒ Object (writeonly)
Sets the attribute do_not_load_root_schedule
9 10 11 |
# File 'lib/schked/config.rb', line 9 def do_not_load_root_schedule=(value) @do_not_load_root_schedule = value end |
#job_run_store ⇒ Object
Returns the value of attribute job_run_store.
89 90 91 |
# File 'lib/schked/config.rb', line 89 def job_run_store @job_run_store end |
#logger ⇒ Object
33 34 35 |
# File 'lib/schked/config.rb', line 33 def logger @logger ||= Logger.new($stdout).tap { |l| l.level = Logger::INFO } end |
#max_skew ⇒ Object
91 92 93 |
# File 'lib/schked/config.rb', line 91 def max_skew @max_skew ||= 60 end |
#redis ⇒ Object
64 65 66 |
# File 'lib/schked/config.rb', line 64 def redis @redis ||= {url: ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379")} end |
#standalone=(value) ⇒ Object (writeonly)
Sets the attribute standalone
9 10 11 |
# File 'lib/schked/config.rb', line 9 def standalone=(value) @standalone = value end |
Instance Method Details
#dedup_enabled? ⇒ Boolean
97 98 99 |
# File 'lib/schked/config.rb', line 97 def dedup_enabled? !@job_run_store.nil? end |
#do_not_load_root_schedule? ⇒ Boolean
37 38 39 |
# File 'lib/schked/config.rb', line 37 def do_not_load_root_schedule? !!@do_not_load_root_schedule end |
#fire_around_callback(name, job, calls = , &block) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/schked/config.rb', line 51 def fire_around_callback(name, job, calls = callbacks[name], &block) return yield if calls.none? calls.first.call(job) do calls = calls.drop(1) if calls.any? fire_around_callback(name, job, calls, &block) else yield end end end |
#fire_callback(name, *args) ⇒ Object
45 46 47 48 49 |
# File 'lib/schked/config.rb', line 45 def fire_callback(name, *args) callbacks[name].each do |callback| callback.call(*args) end end |
#liveness_probe ⇒ Object
17 18 19 |
# File 'lib/schked/config.rb', line 17 def liveness_probe @liveness_probe ||= LivenessProbeConfig.new end |
#liveness_probe=(value) ⇒ Object
21 22 23 |
# File 'lib/schked/config.rb', line 21 def liveness_probe=(value) @liveness_probe = value.is_a?(LivenessProbeConfig) ? value : LivenessProbeConfig.new(value) end |
#logger? ⇒ Boolean
29 30 31 |
# File 'lib/schked/config.rb', line 29 def logger? !!@logger end |
#paths ⇒ Object
25 26 27 |
# File 'lib/schked/config.rb', line 25 def paths @paths ||= [] end |
#redis_servers=(val) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/schked/config.rb', line 68 def redis_servers=(val) val = val.first if val.is_a?(String) self.redis = {url: val} elsif val.respond_to?(:_client) conf = val._client.config self.redis = {url: conf.server_url, username: conf.username, password: conf.password} else raise ArgumentError, "Schked `redis_servers=` config option is deprecated. Please use `redis=` with a Hash" end warn "🔥 Schked `redis_servers=` config option is deprecated. Please use `redis=` with a Hash. Called from #{caller(1..1).first}" end |
#register_callback(name, &block) ⇒ Object
41 42 43 |
# File 'lib/schked/config.rb', line 41 def register_callback(name, &block) callbacks[name] << block end |
#standalone? ⇒ Boolean
83 84 85 86 87 |
# File 'lib/schked/config.rb', line 83 def standalone? @standalone = ENV["RAILS_ENV"] == "test" || ENV["RACK_ENV"] == "test" if @standalone.nil? !!@standalone end |
#validate! ⇒ Object
Validates all configuration options. Called by the worker during initialization so the worker can remain agnostic about which options exist and which combinations are legal.
104 105 106 107 |
# File 'lib/schked/config.rb', line 104 def validate! validate_job_run_store! validate_max_skew! end |