Class: QPush::Server::Worker
- Inherits:
-
Object
- Object
- QPush::Server::Worker
- Includes:
- ObjectValidator::Validate
- Defined in:
- lib/qpush/server/worker.rb
Overview
The Worker manages our workers - Queue, Delay, and Perform. 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
-
#delay_threads ⇒ Object
Returns the value of attribute delay_threads.
-
#id ⇒ Object
Returns the value of attribute id.
-
#perform_threads ⇒ Object
Returns the value of attribute perform_threads.
-
#queue_threads ⇒ Object
Returns the value of attribute queue_threads.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ 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(options = {}) ⇒ Worker
Returns a new instance of Worker.
13 14 15 16 17 18 19 |
# File 'lib/qpush/server/worker.rb', line 13 def initialize( = {}) .each { |key, value| send("#{key}=", value) } @pid = Process.pid @workers = [] @threads = [] at_exit { shutdown } end |
Instance Attribute Details
#delay_threads ⇒ Object
Returns the value of attribute delay_threads.
11 12 13 |
# File 'lib/qpush/server/worker.rb', line 11 def delay_threads @delay_threads end |
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/qpush/server/worker.rb', line 11 def id @id end |
#perform_threads ⇒ Object
Returns the value of attribute perform_threads.
11 12 13 |
# File 'lib/qpush/server/worker.rb', line 11 def perform_threads @perform_threads end |
#queue_threads ⇒ Object
Returns the value of attribute queue_threads.
11 12 13 |
# File 'lib/qpush/server/worker.rb', line 11 def queue_threads @queue_threads end |
Instance Method Details
#shutdown ⇒ Object
Shutsdown our worker as well as its threads.
32 33 34 35 36 |
# File 'lib/qpush/server/worker.rb', line 32 def shutdown @workers.each(&:shutdown) @threads.each(&:exit) end |
#start ⇒ Object
Starts our new worker.
23 24 25 26 27 28 |
# File 'lib/qpush/server/worker.rb', line 23 def start validate! build_threads start_threads end |