Class: QPush::Server::Worker
- Inherits:
-
Object
- Object
- QPush::Server::Worker
- 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
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#initialize(id, config) ⇒ Worker
constructor
A new instance of Worker.
-
#shutdown ⇒ Object
Shutsdown our worker as well as its threads.
-
#start ⇒ Object
Starts our new worker.
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/qpush/server/worker.rb', line 13 def config @config end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/qpush/server/worker.rb', line 13 def id @id end |
#pid ⇒ Object (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
#shutdown ⇒ Object
Shutsdown our worker as well as its threads.
40 41 42 43 44 |
# File 'lib/qpush/server/worker.rb', line 40 def shutdown @actions.each(&:shutdown) @threads.each(&:exit) end |
#start ⇒ Object
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 build_threads start_threads end |