Class: Artery::Worker
- Inherits:
-
Object
- Object
- Artery::Worker
- Defined in:
- lib/artery/worker.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#worker_id ⇒ Object
readonly
Returns the value of attribute worker_id.
Instance Method Summary collapse
-
#initialize ⇒ Worker
constructor
A new instance of Worker.
- #run(services = nil) ⇒ Object
- #subscribe_healthz ⇒ Object
Constructor Details
#initialize ⇒ Worker
Returns a new instance of Worker.
9 10 11 |
# File 'lib/artery/worker.rb', line 9 def initialize @worker_id = SecureRandom.hex end |
Instance Attribute Details
#worker_id ⇒ Object (readonly)
Returns the value of attribute worker_id.
7 8 9 |
# File 'lib/artery/worker.rb', line 7 def worker_id @worker_id end |
Instance Method Details
#run(services = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/artery/worker.rb', line 18 def run(services = nil) services = Array.wrap(services).map(&:to_sym) subscriptions_on_services = services.blank? ? Artery.subscriptions : Artery.subscriptions_on(services) if subscriptions_on_services.blank? Artery.logger.warn 'No suitable subscriptions defined, exiting...' return end Artery.handle_signals @sync = Artery::Sync.new worker_id Artery.worker = self Artery.start { worker_cycle(services, subscriptions_on_services) } ensure Artery.clear_synchronizing_subscriptions! end |
#subscribe_healthz ⇒ Object
13 14 15 16 |
# File 'lib/artery/worker.rb', line 13 def subscribe_healthz HealthzSubscription.new.subscribe WorkerHealthzSubscription.new(worker_id, 'worker').subscribe end |