Class: Pallets::Worker
- Inherits:
-
Object
- Object
- Pallets::Worker
- Defined in:
- lib/pallets/worker.rb
Instance Attribute Summary collapse
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
Instance Method Summary collapse
- #debug ⇒ Object
- #graceful_shutdown ⇒ Object
- #hard_shutdown ⇒ Object
- #id ⇒ Object
-
#initialize(manager) ⇒ Worker
constructor
A new instance of Worker.
- #needs_to_stop? ⇒ Boolean
- #start ⇒ Object
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
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
3 4 5 |
# File 'lib/pallets/worker.rb', line 3 def manager @manager end |
Instance Method Details
#debug ⇒ Object
29 30 31 |
# File 'lib/pallets/worker.rb', line 29 def debug @thread.backtrace end |
#graceful_shutdown ⇒ Object
16 17 18 |
# File 'lib/pallets/worker.rb', line 16 def graceful_shutdown @needs_to_stop = true end |
#hard_shutdown ⇒ Object
20 21 22 23 |
# File 'lib/pallets/worker.rb', line 20 def hard_shutdown return unless @thread @thread.raise Pallets::Shutdown end |
#id ⇒ Object
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
25 26 27 |
# File 'lib/pallets/worker.rb', line 25 def needs_to_stop? @needs_to_stop end |
#start ⇒ Object
12 13 14 |
# File 'lib/pallets/worker.rb', line 12 def start @thread ||= Thread.new { work } end |