Class: Proxy::OpenBolt::Job
- Inherits:
-
Object
- Object
- Proxy::OpenBolt::Job
- Includes:
- Log
- Defined in:
- lib/smart_proxy_openbolt/job.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(name, parameters, options) ⇒ Job
constructor
Valid statuses are :pending - waiting to run :running - in progress :success - job finished as was completely successful :failure - job finished and had one or more failures :exception - command exited with an unexpected code.
-
#process ⇒ Object
Called by worker.
-
#result ⇒ Object
Read the result back from disk as a raw JSON string.
- #store_result(value) ⇒ Object
- #update_status(value) ⇒ Object
Constructor Details
#initialize(name, parameters, options) ⇒ Job
Valid statuses are
:pending - waiting to run
:running - in progress
:success - job finished as was completely successful
:failure - job finished and had one or more failures
:exception - command exited with an unexpected code
17 18 19 20 21 22 23 24 |
# File 'lib/smart_proxy_openbolt/job.rb', line 17 def initialize(name, parameters, ) @id = nil @name = name @parameters = parameters @options = @status = :pending @mutex = Mutex.new end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/smart_proxy_openbolt/job.rb', line 7 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/smart_proxy_openbolt/job.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/smart_proxy_openbolt/job.rb', line 8 def @options end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
8 9 10 |
# File 'lib/smart_proxy_openbolt/job.rb', line 8 def parameters @parameters end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/smart_proxy_openbolt/job.rb', line 8 def status @status end |
Instance Method Details
#execute ⇒ Object
26 27 28 |
# File 'lib/smart_proxy_openbolt/job.rb', line 26 def execute raise NotImplementedError, "You must call #execute on a subclass of Job" end |
#process ⇒ Object
Called by worker. The ‘execute’ function should return a Proxy::OpenBolt::Result object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/smart_proxy_openbolt/job.rb', line 32 def process update_status(:running) begin result = execute update_status(result.status) store_result(result) rescue Exception => e # rubocop:disable Lint/RescueException # Catch everything including non-StandardError exceptions (e.g. # ScriptError) so the job always gets a terminal status. update_status(:exception) logger.error("Job #{@id} failed (#{e.class}): #{e.}") logger.debug(e.backtrace.join("\n")) if e.backtrace begin store_result({ message: e., backtrace: e.backtrace }) rescue StandardError => store_error logger.error("Job #{@id}: failed to store error result: #{store_error.}") logger.debug(store_error.backtrace.join("\n")) if store_error.backtrace end end end |
#result ⇒ Object
Read the result back from disk as a raw JSON string. We avoid parsing and re-serializing since the file is already valid JSON.
63 64 65 |
# File 'lib/smart_proxy_openbolt/job.rb', line 63 def result File.read(Proxy::OpenBolt.result_file_path(@id)) end |
#store_result(value) ⇒ Object
57 58 59 |
# File 'lib/smart_proxy_openbolt/job.rb', line 57 def store_result(value) File.write(Proxy::OpenBolt.result_file_path(@id), value.to_json) end |
#update_status(value) ⇒ Object
53 54 55 |
# File 'lib/smart_proxy_openbolt/job.rb', line 53 def update_status(value) @mutex.synchronize { @status = value } end |