Class: Pallets::Worker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manager) ⇒ Worker

Returns a new instance of Worker.



5
6
7
8
9
10
# File 'lib/pallets/worker.rb', line 5

def initialize(manager)
  @manager = manager
  @current_job = nil
  @needs_to_stop = false
  @thread = nil
end

Instance Attribute Details

#managerObject (readonly)

Returns the value of attribute manager.



3
4
5
# File 'lib/pallets/worker.rb', line 3

def manager
  @manager
end

Instance Method Details

#debugObject



29
30
31
# File 'lib/pallets/worker.rb', line 29

def debug
  @thread.backtrace
end

#graceful_shutdownObject



16
17
18
# File 'lib/pallets/worker.rb', line 16

def graceful_shutdown
  @needs_to_stop = true
end

#hard_shutdownObject



20
21
22
23
# File 'lib/pallets/worker.rb', line 20

def hard_shutdown
  return unless @thread
  @thread.raise Pallets::Shutdown
end

#idObject



33
34
35
# File 'lib/pallets/worker.rb', line 33

def id
  "W#{@thread.object_id.to_s(36)}".upcase if @thread
end

#needs_to_stop?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/pallets/worker.rb', line 25

def needs_to_stop?
  @needs_to_stop
end

#startObject



12
13
14
# File 'lib/pallets/worker.rb', line 12

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