Class: Ocular::Inputs::Cron::Input

Inherits:
Base
  • Object
show all
Defined in:
lib/ocular/inputs/cron_input.rb

Defined Under Namespace

Classes: DSLProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings_factory) ⇒ Input

Returns a new instance of Input.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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

Instance Attribute Details

#cron_enabledObject (readonly)

Returns the value of attribute cron_enabled.



29
30
31
# File 'lib/ocular/inputs/cron_input.rb', line 29

def cron_enabled
  @cron_enabled
end

#routesObject (readonly)

Returns the value of attribute routes.



27
28
29
# File 'lib/ocular/inputs/cron_input.rb', line 27

def routes
  @routes
end

#schedulerObject (readonly)

Returns the value of attribute scheduler.



28
29
30
# File 'lib/ocular/inputs/cron_input.rb', line 28

def scheduler
  @scheduler
end

Instance Method Details

#disableObject



65
66
67
# File 'lib/ocular/inputs/cron_input.rb', line 65

def disable()
    @cron_enabled = false
end

#enableObject



69
70
71
# File 'lib/ocular/inputs/cron_input.rb', line 69

def enable()
    @cron_enabled = true
end

#startObject



57
58
59
# File 'lib/ocular/inputs/cron_input.rb', line 57

def start()

end

#stopObject



61
62
63
# File 'lib/ocular/inputs/cron_input.rb', line 61

def stop()
    @scheduler.shutdown
end