Class: Ductwork::Processes::PipelineAdvancer
- Inherits:
-
Object
- Object
- Ductwork::Processes::PipelineAdvancer
- Defined in:
- lib/ductwork/processes/pipeline_advancer.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#last_heartbeat_at ⇒ Object
readonly
Returns the value of attribute last_heartbeat_at.
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(klass, index = nil) ⇒ PipelineAdvancer
constructor
A new instance of PipelineAdvancer.
- #join(limit) ⇒ Object
- #kill ⇒ Object
- #name ⇒ Object
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #stuck? ⇒ Boolean
Constructor Details
#initialize(klass, index = nil) ⇒ PipelineAdvancer
Returns a new instance of PipelineAdvancer.
8 9 10 11 12 13 14 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 8 def initialize(klass, index = nil) @klass = klass @index = index || 0 @running_context = nil @last_heartbeat_at = Time.current @thread = nil end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
6 7 8 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 6 def branch @branch end |
#last_heartbeat_at ⇒ Object (readonly)
Returns the value of attribute last_heartbeat_at.
6 7 8 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 6 def last_heartbeat_at @last_heartbeat_at end |
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
6 7 8 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 6 def thread @thread end |
Instance Method Details
#alive? ⇒ Boolean
34 35 36 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 34 def alive? thread&.alive? || false end |
#join(limit) ⇒ Object
51 52 53 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 51 def join(limit) thread&.join(limit) end |
#kill ⇒ Object
46 47 48 49 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 46 def kill stop thread&.kill end |
#name ⇒ Object
55 56 57 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 55 def name "ductwork.pipeline_advancer.#{klass}.#{index}" end |
#restart ⇒ Object
27 28 29 30 31 32 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 27 def restart return false if alive? cleanup_dead_thread! start end |
#start ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 16 def start return false if alive? @running_context = Ductwork::RunningContext.new @last_heartbeat_at = Time.current @thread = Thread.new { work_loop } @thread.name = name true end |
#stop ⇒ Object
42 43 44 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 42 def stop running_context&.shutdown! end |
#stuck? ⇒ Boolean
38 39 40 |
# File 'lib/ductwork/processes/pipeline_advancer.rb', line 38 def stuck? branch.nil? && last_heartbeat_too_long_ago? end |