Class: RocketJob::Subscribers::Worker

Inherits:
Object
  • Object
show all
Includes:
RocketJob::Subscriber
Defined in:
lib/rocket_job/subscribers/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RocketJob::Subscriber

#process_action, #process_event, test_mode!, test_mode?

Constructor Details

#initialize(supervisor) ⇒ Worker

Returns a new instance of Worker.



8
9
10
# File 'lib/rocket_job/subscribers/worker.rb', line 8

def initialize(supervisor)
  @supervisor = supervisor
end

Instance Attribute Details

#supervisorObject (readonly)

Returns the value of attribute supervisor.



6
7
8
# File 'lib/rocket_job/subscribers/worker.rb', line 6

def supervisor
  @supervisor
end

Instance Method Details

#kill(server_id:, worker_id:, wait_timeout: 3) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rocket_job/subscribers/worker.rb', line 12

def kill(server_id:, worker_id:, wait_timeout: 3)
  return unless my_server?(server_id)

  worker = locate_worker(worker_id)
  return unless worker

  worker.shutdown!
  worker.join(wait_timeout)
  worker.kill

  logger.info "Killed"
end

#stop(server_id:, worker_id:) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/rocket_job/subscribers/worker.rb', line 25

def stop(server_id:, worker_id:)
  return unless my_server?(server_id)

  worker = locate_worker(worker_id)
  return unless worker

  worker.shutdown!
  logger.info "Stopped Worker: #{worker_id}"
end

#thread_dump(server_id:, worker_id:) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/rocket_job/subscribers/worker.rb', line 35

def thread_dump(server_id:, worker_id:)
  return unless my_server?(server_id)

  worker = locate_worker(worker_id)
  return unless worker

  logger.info "Thread dump Worker: #{worker_id}"
  logger.backtrace(thread: worker.thread) if worker.thread && worker.alive?
end