module DashingContrib::RunnableJob

Constants

CRITICAL
OK
WARNING

Public Instance Methods

metrics(options) click to toggle source

Overrides this method to fetch and generate metrics Return value should be the final metrics to be used in the user interface Arguments:

options :: options provided by caller in `run` method
# File lib/dashing-contrib/runnable_job.rb, line 60
def metrics(options)
  {}
end
run(options = {}, &block) click to toggle source
# File lib/dashing-contrib/runnable_job.rb, line 39
def run(options = {}, &block)
  user_options = _merge_options(options)
  interval     = user_options.delete(:every)
  scheduler_opts = user_options.delete(:scheduler) || {}

  ## Keep this for compatibility.
  #   Note: :first_in inside the :scheduler hash will override this.
  rufus_opt = {
    first_in: user_options[:first_in]
  }
  rufus_opt.merge!(scheduler_opts)

  event_name   = user_options.delete(:event)
  block.call if block_given?
  Context.new(interval, rufus_opt, event_name, user_options, self).schedule!
end
validate_state(metrics, user_options) click to toggle source

Always return a common state, override this with your custom logic Common states are WARNING, CRITICAL, OK Arguments:

metrics :: calculated metrics provided `metrics` method
user_options :: hash provided by user options
# File lib/dashing-contrib/runnable_job.rb, line 69
def validate_state(metrics, user_options)
  OK
end

Private Instance Methods

_default_scheduler_options() click to toggle source
# File lib/dashing-contrib/runnable_job.rb, line 79
def _default_scheduler_options
  {
    every: '30s',
    first_in: 0
  }
end
_merge_options(options) click to toggle source
# File lib/dashing-contrib/runnable_job.rb, line 74
def _merge_options(options)
  raise ':event String is required to identify a job name' if options[:event].nil?
  _default_scheduler_options.merge(options)
end