Class: WhoCan::Heartbeater::Beat
- Inherits:
-
Object
- Object
- WhoCan::Heartbeater::Beat
- Includes:
- Deferred, Logging
- Defined in:
- lib/who_can/heartbeater/beat.rb
Instance Attribute Summary collapse
-
#beat_id ⇒ Object
readonly
Returns the value of attribute beat_id.
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
-
#timeout_after ⇒ Object
readonly
Returns the value of attribute timeout_after.
Instance Method Summary collapse
- #cancel! ⇒ Object
- #cancelled? ⇒ Boolean
- #fired? ⇒ Boolean
-
#initialize(channel, queue, beat_id, timeout = nil) ⇒ Beat
constructor
A new instance of Beat.
- #pending? ⇒ Boolean
- #ping_received! ⇒ Object
- #start! ⇒ Object
Methods included from Logging
Constructor Details
#initialize(channel, queue, beat_id, timeout = nil) ⇒ Beat
Returns a new instance of Beat.
21 22 23 24 25 26 27 |
# File 'lib/who_can/heartbeater/beat.rb', line 21 def initialize(channel, queue, beat_id, timeout=nil) @channel = channel @queue = queue @beat_id = beat_id @timeout_after = timeout @started = false end |
Instance Attribute Details
#beat_id ⇒ Object (readonly)
Returns the value of attribute beat_id.
10 11 12 |
# File 'lib/who_can/heartbeater/beat.rb', line 10 def beat_id @beat_id end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
10 11 12 |
# File 'lib/who_can/heartbeater/beat.rb', line 10 def channel @channel end |
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
10 11 12 |
# File 'lib/who_can/heartbeater/beat.rb', line 10 def queue @queue end |
#timeout_after ⇒ Object (readonly)
Returns the value of attribute timeout_after.
10 11 12 |
# File 'lib/who_can/heartbeater/beat.rb', line 10 def timeout_after @timeout_after end |
Instance Method Details
#cancel! ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/who_can/heartbeater/beat.rb', line 37 def cancel! return if fired? logger.info { "#{beat_id} cancel called!" } cancel_timeout @cancelled = true succeed end |
#cancelled? ⇒ Boolean
47 48 49 |
# File 'lib/who_can/heartbeater/beat.rb', line 47 def cancelled? @cancelled end |
#fired? ⇒ Boolean
33 34 35 |
# File 'lib/who_can/heartbeater/beat.rb', line 33 def fired? !pending? end |
#pending? ⇒ Boolean
29 30 31 |
# File 'lib/who_can/heartbeater/beat.rb', line 29 def pending? @deferred_status.nil? or (@deferred_status == :unknown) end |
#ping_received! ⇒ Object
51 52 53 |
# File 'lib/who_can/heartbeater/beat.rb', line 51 def ping_received! succeed if pending? and not cancelled? end |
#start! ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/who_can/heartbeater/beat.rb', line 55 def start! return if @started @started = true timeout(timeout_after) if timeout_after channel.once_opened do errback_on_exception do channel.default_exchange.publish('BEAT', :routing_key => queue.name, :message_id => beat_id) do logger.debug { "message #{beat_id} sent" } after_publish.succeed end end end end |