Class: QPush::Server::Worker

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

Overview

The Worker manages our actions - Queue, Delay, Perform and Heartbeat. Each of these actions is alloted a number of threads. Each action 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.



24
25
26
27
28
29
30
31
# File 'lib/qpush/server/worker.rb', line 24

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.



22
23
24
# File 'lib/qpush/server/worker.rb', line 22

def config
  @config
end

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/qpush/server/worker.rb', line 22

def id
  @id
end

#pidObject (readonly)

Returns the value of attribute pid.



22
23
24
# File 'lib/qpush/server/worker.rb', line 22

def pid
  @pid
end

Instance Method Details

#shutdownObject

Shutsdown our worker as well as its threads.



45
46
47
48
49
# File 'lib/qpush/server/worker.rb', line 45

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

#startObject

Starts our new worker.



35
36
37
38
39
40
41
# File 'lib/qpush/server/worker.rb', line 35

def start
  assign_globals
  register_space
  start_message
  build_actions
  start_threads
end