Class: Pubilion::Worker::Subscriber
- Inherits:
-
Object
- Object
- Pubilion::Worker::Subscriber
- Defined in:
- lib/pubilion/worker/subscriber.rb
Overview
Subscriber on Pubilion
Constant Summary collapse
- SHUTDOWN_WAIT =
20
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Check if subscriber is alive.
-
#initialize(config, handler) ⇒ Subscriber
constructor
A new instance of Subscriber.
-
#run ⇒ Object
Start streaming pull subscribe.
-
#shutdown ⇒ Object
Stop streaming pull subscribe.
-
#stopped? ⇒ Boolean
Check if subscriber is stopped.
Constructor Details
#initialize(config, handler) ⇒ Subscriber
Returns a new instance of Subscriber.
13 14 15 16 |
# File 'lib/pubilion/worker/subscriber.rb', line 13 def initialize(config, handler) @config = config @handler = handler end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/pubilion/worker/subscriber.rb', line 11 def config @config end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
11 12 13 |
# File 'lib/pubilion/worker/subscriber.rb', line 11 def handler @handler end |
Instance Method Details
#alive? ⇒ Boolean
Check if subscriber is alive.
37 38 39 |
# File 'lib/pubilion/worker/subscriber.rb', line 37 def alive? @subscriber.started? && !@subscriber.stopped? end |
#run ⇒ Object
Start streaming pull subscribe.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pubilion/worker/subscriber.rb', line 19 def run @subscriber = subscription.listen do || handler.() end @subscriber.on_error do |error| handler.on_error(error) end @subscriber.start end |
#shutdown ⇒ Object
Stop streaming pull subscribe.
32 33 34 |
# File 'lib/pubilion/worker/subscriber.rb', line 32 def shutdown @subscriber&.stop&.wait!(SHUTDOWN_WAIT) end |
#stopped? ⇒ Boolean
Check if subscriber is stopped.
42 43 44 |
# File 'lib/pubilion/worker/subscriber.rb', line 42 def stopped? @subscriber.stopped? end |