Class: DatWorkerPool::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/dat-worker-pool/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue) ⇒ Worker

Returns a new instance of Worker.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dat-worker-pool/worker.rb', line 13

def initialize(queue)
  @queue = queue
  @on_work = proc{ |worker, work_item| }
  @on_error_callbacks    = []
  @on_start_callbacks    = []
  @on_shutdown_callbacks = []
  @on_sleep_callbacks    = []
  @on_wakeup_callbacks   = []
  @before_work_callbacks = []
  @after_work_callbacks  = []

  @shutdown = false
  @thread   = nil
end

Instance Attribute Details

#after_work_callbacksObject

Returns the value of attribute after_work_callbacks.



11
12
13
# File 'lib/dat-worker-pool/worker.rb', line 11

def after_work_callbacks
  @after_work_callbacks
end

#before_work_callbacksObject

Returns the value of attribute before_work_callbacks.



11
12
13
# File 'lib/dat-worker-pool/worker.rb', line 11

def before_work_callbacks
  @before_work_callbacks
end

#on_error_callbacksObject

Returns the value of attribute on_error_callbacks.



8
9
10
# File 'lib/dat-worker-pool/worker.rb', line 8

def on_error_callbacks
  @on_error_callbacks
end

#on_shutdown_callbacksObject

Returns the value of attribute on_shutdown_callbacks.



9
10
11
# File 'lib/dat-worker-pool/worker.rb', line 9

def on_shutdown_callbacks
  @on_shutdown_callbacks
end

#on_sleep_callbacksObject

Returns the value of attribute on_sleep_callbacks.



10
11
12
# File 'lib/dat-worker-pool/worker.rb', line 10

def on_sleep_callbacks
  @on_sleep_callbacks
end

#on_start_callbacksObject

Returns the value of attribute on_start_callbacks.



9
10
11
# File 'lib/dat-worker-pool/worker.rb', line 9

def on_start_callbacks
  @on_start_callbacks
end

#on_wakeup_callbacksObject

Returns the value of attribute on_wakeup_callbacks.



10
11
12
# File 'lib/dat-worker-pool/worker.rb', line 10

def on_wakeup_callbacks
  @on_wakeup_callbacks
end

#on_workObject

Returns the value of attribute on_work.



8
9
10
# File 'lib/dat-worker-pool/worker.rb', line 8

def on_work
  @on_work
end

Instance Method Details

#join(*args) ⇒ Object



40
41
42
# File 'lib/dat-worker-pool/worker.rb', line 40

def join(*args)
  @thread.join(*args) if running?
end

#raise(*args) ⇒ Object



44
45
46
# File 'lib/dat-worker-pool/worker.rb', line 44

def raise(*args)
  @thread.raise(*args) if running?
end

#running?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/dat-worker-pool/worker.rb', line 36

def running?
  !!(@thread && @thread.alive?)
end

#shutdownObject



32
33
34
# File 'lib/dat-worker-pool/worker.rb', line 32

def shutdown
  @shutdown = true
end

#startObject



28
29
30
# File 'lib/dat-worker-pool/worker.rb', line 28

def start
  @thread ||= Thread.new{ work_loop }
end