Class: QPush::Server::Worker

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options = {})
  options.each { |key, value| send("#{key}=", value) }
  @pid = Process.pid
  @workers = []
  @threads = []
  at_exit { shutdown }
end

Instance Attribute Details

#delay_threadsObject

Returns the value of attribute delay_threads.



11
12
13
# File 'lib/qpush/server/worker.rb', line 11

def delay_threads
  @delay_threads
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/qpush/server/worker.rb', line 11

def id
  @id
end

#perform_threadsObject

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_threadsObject

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

#shutdownObject

Shutsdown our worker as well as its threads.



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

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

#startObject

Starts our new worker.



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

def start
  validate!
  start_message
  build_threads
  start_threads
end