Class: Plotlyrb::PlotImage::AsyncJob
- Inherits:
-
Struct
- Object
- Struct
- Plotlyrb::PlotImage::AsyncJob
- Defined in:
- lib/plotlyrb/plot_image.rb
Instance Attribute Summary collapse
-
#spec_path ⇒ Object
Returns the value of attribute spec_path.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#thread ⇒ Object
Returns the value of attribute thread.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#spec_path ⇒ Object
Returns the value of attribute spec_path
33 34 35 |
# File 'lib/plotlyrb/plot_image.rb', line 33 def spec_path @spec_path end |
#start_time ⇒ Object
Returns the value of attribute start_time
33 34 35 |
# File 'lib/plotlyrb/plot_image.rb', line 33 def start_time @start_time end |
#thread ⇒ Object
Returns the value of attribute thread
33 34 35 |
# File 'lib/plotlyrb/plot_image.rb', line 33 def thread @thread end |
#timeout ⇒ Object
Returns the value of attribute timeout
33 34 35 |
# File 'lib/plotlyrb/plot_image.rb', line 33 def timeout @timeout end |
Class Method Details
.from_spec_path(pi, spec_path, timeout) ⇒ Object
34 35 36 37 |
# File 'lib/plotlyrb/plot_image.rb', line 34 def self.from_spec_path(pi, spec_path, timeout) thread = Thread.new { pi.plot_image(spec_path.spec, spec_path.path) } new(thread, spec_path, Time.new, timeout) end |
Instance Method Details
#fail(msg) ⇒ Object
43 44 45 |
# File 'lib/plotlyrb/plot_image.rb', line 43 def fail(msg) AsyncJobResult.new(false, msg, spec_path) end |
#join ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/plotlyrb/plot_image.rb', line 39 def join now = Time.new join_wait = (self.timeout - (now - self.start_time)).to_i + 1 def fail(msg) AsyncJobResult.new(false, msg, spec_path) end # Joining should bubble any exceptions, so catch them and report the failure as an error begin if thread.join(join_wait).nil? thread.exit return fail("thread didn't finish within timeout (#{timeout}s)") end response = thread.value unless response.success return fail("Plotly returned error response: #{response}") end unless File.exist?(spec_path.path) return fail("Output file (#{spec_path.path}) not found") end rescue => e return fail(e.) end AsyncJobResult.new(true, '', spec_path) end |