Class: Artery::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/artery/worker.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorker

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_idObject (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_healthzObject



13
14
15
16
# File 'lib/artery/worker.rb', line 13

def subscribe_healthz
  HealthzSubscription.new.subscribe
  WorkerHealthzSubscription.new(worker_id, 'worker').subscribe
end