Class: QPush::Server::Worker

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
ObjectValidator::Validate
Defined in:
lib/qpush/server/worker.rb

Overview

The Worker manages our workers - Queue, Delay, Perform and Heartbeat. Each of these workers is alloted a number of threads. Each worker object maintains control of these threads through the aptly named start and shutdown methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, config) ⇒ Worker

Returns a new instance of Worker.



18
19
20
21
22
23
24
25
# File 'lib/qpush/server/worker.rb', line 18

def initialize(id, config)
  @id = id
  @pid = Process.pid
  @config = config
  @actions = []
  @threads = []
  at_exit { shutdown }
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/qpush/server/worker.rb', line 13

def config
  @config
end

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/qpush/server/worker.rb', line 13

def id
  @id
end

#pidObject (readonly)

Returns the value of attribute pid.



13
14
15
# File 'lib/qpush/server/worker.rb', line 13

def pid
  @pid
end

Instance Method Details

#shutdownObject

Shutsdown our worker as well as its threads.



40
41
42
43
44
# File 'lib/qpush/server/worker.rb', line 40

def shutdown
  shutdown_message
  @actions.each(&:shutdown)
  @threads.each(&:exit)
end

#startObject

Starts our new worker.



29
30
31
32
33
34
35
36
# File 'lib/qpush/server/worker.rb', line 29

def start
  validate!
  assign_globals
  register_space
  start_message
  build_threads
  start_threads
end