Class: Pallets::Worker

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

Instance Method Summary collapse

Constructor Details

#initialize(manager, backend) ⇒ Worker

Returns a new instance of Worker.



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

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

Instance Method Details

#debugObject



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

def debug
  @thread.backtrace
end

#graceful_shutdownObject



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

def graceful_shutdown
  @needs_to_stop = true
end

#hard_shutdownObject



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

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

#idObject



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

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

#needs_to_stop?Boolean

Returns:

  • (Boolean)


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

def needs_to_stop?
  @needs_to_stop
end

#startObject



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

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