Class: Elected::Scheduler::Poller
- Inherits:
-
Object
- Object
- Elected::Scheduler::Poller
- Extended by:
- Forwardable
- Includes:
- Logging
- Defined in:
- lib/elected/scheduler/poller.rb
Instance Attribute Summary collapse
-
#jobs ⇒ Object
readonly
Returns the value of attribute jobs.
-
#key ⇒ Object
Returns the value of attribute key.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #add(job) ⇒ Object (also: #<<)
-
#initialize(key, timeout = nil) ⇒ Poller
constructor
A new instance of Poller.
- #leader? ⇒ Boolean
- #running? ⇒ Boolean
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(key, timeout = nil) ⇒ Poller
Returns a new instance of Poller.
13 14 15 16 17 18 |
# File 'lib/elected/scheduler/poller.rb', line 13 def initialize(key, timeout = nil) @senado ||= Senado.new key, timeout @key = key @jobs = Concurrent::Hash.new @stats = Stats.new :processed_job, :no_match, :sleep_slave end |
Instance Attribute Details
#jobs ⇒ Object (readonly)
Returns the value of attribute jobs.
9 10 11 |
# File 'lib/elected/scheduler/poller.rb', line 9 def jobs @jobs end |
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/elected/scheduler/poller.rb', line 8 def key @key end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
9 10 11 |
# File 'lib/elected/scheduler/poller.rb', line 9 def stats @stats end |
Instance Method Details
#add(job) ⇒ Object Also known as: <<
20 21 22 23 |
# File 'lib/elected/scheduler/poller.rb', line 20 def add(job) @jobs[job.name] = job self end |
#leader? ⇒ Boolean
63 64 65 |
# File 'lib/elected/scheduler/poller.rb', line 63 def leader? senado.leader? end |
#running? ⇒ Boolean
31 32 33 |
# File 'lib/elected/scheduler/poller.rb', line 31 def running? status == :running end |
#start ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/elected/scheduler/poller.rb', line 39 def start return false unless stopped? raise 'No jobs to run!' if jobs.empty? debug "#{label} starting ..." @status = :starting start_polling_loop @status = :running debug "#{label} running poller!" @status end |
#status ⇒ Object
27 28 29 |
# File 'lib/elected/scheduler/poller.rb', line 27 def status @status ||= :stopped end |
#stop ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/elected/scheduler/poller.rb', line 51 def stop return false unless running? debug "#{label} stopping poller ..." @status = :stopping stop_polling_loop senado.release @status = :stopped debug "#{label} stopped poller!" @status end |
#stopped? ⇒ Boolean
35 36 37 |
# File 'lib/elected/scheduler/poller.rb', line 35 def stopped? status == :stopped end |
#to_s ⇒ Object Also known as: inspect
67 68 69 |
# File 'lib/elected/scheduler/poller.rb', line 67 def to_s %{#<#{self.class.name} key="#{key}" timeout="#{timeout}" jobs=#{jobs.size}>} end |