Class: Schked::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/schked/config.rb

Constant Summary collapse

VALID_JOB_RUN_STORES =
%i[redis database].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#database_connectionObject

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

Parameters:

  • value

    the value to set the attribute do_not_load_root_schedule to.



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_storeObject

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

#loggerObject



33
34
35
# File 'lib/schked/config.rb', line 33

def logger
  @logger ||= Logger.new($stdout).tap { |l| l.level = Logger::INFO }
end

#max_skewObject



91
92
93
# File 'lib/schked/config.rb', line 91

def max_skew
  @max_skew ||= 60
end

#redisObject



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

Parameters:

  • value

    the value to set the attribute standalone to.



9
10
11
# File 'lib/schked/config.rb', line 9

def standalone=(value)
  @standalone = value
end

Instance Method Details

#dedup_enabled?Boolean

Returns:

  • (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

Returns:

  • (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_probeObject



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

Returns:

  • (Boolean)


29
30
31
# File 'lib/schked/config.rb', line 29

def logger?
  !!@logger
end

#pathsObject



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

Returns:

  • (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