Class: Pallets::Worker
- Inherits:
-
Object
- Object
- Pallets::Worker
- Defined in:
- lib/pallets/worker.rb
Instance Method Summary collapse
- #debug ⇒ Object
- #graceful_shutdown ⇒ Object
- #hard_shutdown ⇒ Object
- #id ⇒ Object
-
#initialize(manager, backend) ⇒ Worker
constructor
A new instance of Worker.
- #needs_to_stop? ⇒ Boolean
- #start ⇒ Object
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
#debug ⇒ Object
28 29 30 |
# File 'lib/pallets/worker.rb', line 28 def debug @thread.backtrace end |
#graceful_shutdown ⇒ Object
15 16 17 |
# File 'lib/pallets/worker.rb', line 15 def graceful_shutdown @needs_to_stop = true end |
#hard_shutdown ⇒ Object
19 20 21 22 |
# File 'lib/pallets/worker.rb', line 19 def hard_shutdown return unless @thread @thread.raise Pallets::Shutdown end |
#id ⇒ Object
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
24 25 26 |
# File 'lib/pallets/worker.rb', line 24 def needs_to_stop? @needs_to_stop end |
#start ⇒ Object
11 12 13 |
# File 'lib/pallets/worker.rb', line 11 def start @thread ||= Thread.new { work } end |