Class: Proxy::Dynflow::Runner::Base
- Inherits:
-
Object
- Object
- Proxy::Dynflow::Runner::Base
- Defined in:
- lib/smart_proxy_dynflow/runner/base.rb
Overview
Runner is an object that is able to initiate some action and provide update data on refresh call.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
- #logger ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
- #dispatch_exception(context, exception) ⇒ Object
-
#external_event(_event) ⇒ Object
by default, external event just causes the refresh to be triggered: this allows the descendants of the Base to add custom logic to process the external events.
- #generate_updates ⇒ Object
-
#initialize(*_args, suspended_action: nil) ⇒ Base
constructor
A new instance of Base.
- #initialize_continuous_outputs ⇒ Object
- #kill ⇒ Object
- #new_update(data, exit_status) ⇒ Object
- #no_update ⇒ Object
- #publish_data(data, type) ⇒ Object
- #publish_exception(context, exception, fatal = true) ⇒ Object
- #publish_exit_status(status) ⇒ Object
- #refresh ⇒ Object
- #run_refresh ⇒ Object
- #start ⇒ Object
- #timeout ⇒ Object
- #timeout_interval ⇒ Object
Constructor Details
#initialize(*_args, suspended_action: nil) ⇒ Base
Returns a new instance of Base.
9 10 11 12 13 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 9 def initialize(*_args, suspended_action: nil) @suspended_action = suspended_action @id = SecureRandom.uuid initialize_continuous_outputs end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 6 def id @id end |
#logger ⇒ Object
15 16 17 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 15 def logger @logger ||= Logger.new(STDERR) end |
Instance Method Details
#close ⇒ Object
44 45 46 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 44 def close # if cleanup is needed end |
#dispatch_exception(context, exception) ⇒ Object
74 75 76 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 74 def dispatch_exception(context, exception) @continuous_output.add_exception(context, exception) end |
#external_event(_event) ⇒ Object
by default, external event just causes the refresh to be triggered: this allows the descendants of the Base to add custom logic to process the external events. Similarly as ‘run_refresh`, it’s expected to return updates to be dispatched.
28 29 30 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 28 def external_event(_event) run_refresh end |
#generate_updates ⇒ Object
78 79 80 81 82 83 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 78 def generate_updates return no_update if @continuous_output.empty? && @exit_status.nil? new_data = @continuous_output @continuous_output = Proxy::Dynflow::ContinuousOutput.new new_update(new_data, @exit_status) end |
#initialize_continuous_outputs ⇒ Object
93 94 95 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 93 def initialize_continuous_outputs @continuous_output = ::Proxy::Dynflow::ContinuousOutput.new end |
#kill ⇒ Object
40 41 42 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 40 def kill # Override when you can kill the runner in the middle end |
#new_update(data, exit_status) ⇒ Object
89 90 91 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 89 def new_update(data, exit_status) { @suspended_action => Runner::Update.new(data, exit_status) } end |
#no_update ⇒ Object
85 86 87 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 85 def no_update {} end |
#publish_data(data, type) ⇒ Object
59 60 61 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 59 def publish_data(data, type) @continuous_output.add_output(data, type) end |
#publish_exception(context, exception, fatal = true) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 63 def publish_exception(context, exception, fatal = true) logger.error("#{context} - #{exception.class} #{exception.}:\n" + \ exception.backtrace.join("\n")) dispatch_exception context, exception publish_exit_status('EXCEPTION') if fatal end |
#publish_exit_status(status) ⇒ Object
70 71 72 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 70 def publish_exit_status(status) @exit_status = status end |
#refresh ⇒ Object
36 37 38 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 36 def refresh raise NotImplementedError end |
#run_refresh ⇒ Object
19 20 21 22 23 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 19 def run_refresh logger.debug('refreshing runner') refresh generate_updates end |
#start ⇒ Object
32 33 34 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 32 def start raise NotImplementedError end |
#timeout ⇒ Object
48 49 50 51 52 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 48 def timeout # Override when timeouts and regular kills should be handled differently publish_data('Timeout for execution passed, trying to stop the job', 'debug') kill end |
#timeout_interval ⇒ Object
54 55 56 57 |
# File 'lib/smart_proxy_dynflow/runner/base.rb', line 54 def timeout_interval # A number of seconds after which the runner should receive a #timeout # or nil for no timeout end |