class Ocular::Inputs::Cron::Input

Attributes

cron_enabled[R]
routes[R]
scheduler[R]

Public Class Methods

new(settings_factory) click to toggle source
# File lib/ocular/inputs/cron_input.rb, line 31
def initialize(settings_factory)
    settings = settings_factory.get(:inputs).fetch(:cron, {})
    @cron_enabled = true

    if settings[:lock]
        @cron_enabled = false
    end

    if settings[:enabled] == false
        ::Ocular.logger.info "Cron is disabled from settings"
        @cron_enabled = false
    end

    @scheduler = ::Rufus::Scheduler.new
    ::Ocular.logger.debug "Starting Rufus cron scheduler"

    if settings[:lock] and @cron_enabled == true
        Ocular.logger.debug "Enabling cron locking at pid #{Process.pid.to_s}"
        @scheduler.every(settings[:lock_delay] || "10s", :overlap => false) do
            c = Class.new.extend(Ocular::DSL::Etcd)

            @cron_enabled = c.ttl_lock("cron_input", ttl:20)
        end
    end
end

Public Instance Methods

disable() click to toggle source
# File lib/ocular/inputs/cron_input.rb, line 65
def disable()
    @cron_enabled = false
end
enable() click to toggle source
# File lib/ocular/inputs/cron_input.rb, line 69
def enable()
    @cron_enabled = true
end
start() click to toggle source
# File lib/ocular/inputs/cron_input.rb, line 57
def start()

end
stop() click to toggle source
# File lib/ocular/inputs/cron_input.rb, line 61
def stop()
    @scheduler.shutdown
end