class Remon::Config

Constants

LOAD_PATHS

Public Class Methods

new(config_file: nil, config_dir: nil, load_paths: []) click to toggle source
# File lib/remon/config.rb, line 15
def initialize(config_file: nil, config_dir: nil, load_paths: [])
  @config_file = config_file
  @config_dir = config_dir
  @schedule = {}
  @scheduler_offset = 0
  @workers = 1
  @task_group = { interval: 0, offset: 15, randomize: false }
  load_paths = Set.new(load_paths).merge(LOAD_PATHS)
  @dsl = CheckDsl.new load_paths.to_a
end

Public Instance Methods

config() click to toggle source
# File lib/remon/config.rb, line 26
def config
  @config_read ||= begin
    read_config
    true
  end
  {
    schedule: @schedule,
    scheduler_offset: @scheduler_offset,
    process_proc: @process_proc,
    workers: @workers
  }
end

Private Instance Methods

default_ttl(interval) click to toggle source
# File lib/remon/config.rb, line 78
def default_ttl(interval)
  3 * interval
end
every(secs, randomize: false, offset: 0) { || ... } click to toggle source
# File lib/remon/config.rb, line 47
def every(secs, randomize: false, offset: 0, &block)
  raise Error, "offset must be less than interval" if offset > secs
  before = @task_group
  @task_group = { interval: secs, offset: offset, randomize: randomize }
  yield
ensure
  @task_group = before
end
host(host) click to toggle source
# File lib/remon/config.rb, line 43
def host(host)
  Remon.host = host
end
process_event(&block) click to toggle source
# File lib/remon/config.rb, line 60
def process_event(&block)
  @process_proc = block
end
read_config() click to toggle source
# File lib/remon/config.rb, line 82
def read_config
  read_config_file @config_file if @config_file
  if @config_dir
    Dir.glob("#{@config_dir}/*.rb").each { |f| read_config_file f }
  end
end
read_config_file(file) click to toggle source
# File lib/remon/config.rb, line 89
def read_config_file(file)
  if not File.readable? file
    raise Error, "config #{file} not readable"
  end
  instance_eval(File.read(file))
rescue NoMethodError => e
  raise Error, "invalid option used in config: #{e.name}"
end
run_check(check, args = [], kwargs = {})
Alias for: schedule_check
schedule_check(check, args = [], kwargs = {}) click to toggle source
# File lib/remon/config.rb, line 68
def schedule_check(check, args = [], kwargs = {})
  @schedule[@task_group] ||= Set.new
  if not check.is_a? Check
    kwargs[:ttl] ||= default_ttl(@task_group[:interval])
    klass = self.check(check)
    check = klass.new(*args, **kwargs)
  end
  @schedule[@task_group] << check
end
Also aliased as: run_check
scheduler_offset(offset) click to toggle source
# File lib/remon/config.rb, line 56
def scheduler_offset(offset)
  @scheduler_offset = offset
end
workers(workers) click to toggle source
# File lib/remon/config.rb, line 64
def workers(workers)
  @workers = workers
end