Class: ActiveHook::Server::Worker

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

Overview

The Worker manages our two main processes - Queue and Retry. Each of these processes is alloted a number of threads. These threads are then forked. 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



11
12
13
14
15
16
17
# File 'lib/activehook/server/worker.rb', line 11

def initialize(options = {})
  options.each { |key, value| send("#{key}=", value) }
  @pid = Process.pid
  @threads = []
  @_threads_real = []
  at_exit { shutdown }
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/activehook/server/worker.rb', line 9

def id
  @id
end

#queue_threadsObject

Returns the value of attribute queue_threads.



9
10
11
# File 'lib/activehook/server/worker.rb', line 9

def queue_threads
  @queue_threads
end

#retry_threadsObject

Returns the value of attribute retry_threads.



9
10
11
# File 'lib/activehook/server/worker.rb', line 9

def retry_threads
  @retry_threads
end

Instance Method Details

#shutdownObject

Shutsdown our worker as well as its threads.



30
31
32
33
34
# File 'lib/activehook/server/worker.rb', line 30

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

#startObject

Starts our new worker.



21
22
23
24
25
26
# File 'lib/activehook/server/worker.rb', line 21

def start
  validate!
  start_message
  build_threads
  start_threads
end