Class: MiOS::Job
- Inherits:
-
Object
- Object
- MiOS::Job
- Defined in:
- lib/mios/job.rb
Constant Summary collapse
- STATUS =
{ -1 => 'Nonexistent', 0 => 'Waiting', 1 => 'In progress', 2 => 'Error', 3 => 'Aborted', 4 => 'Completed', 5 => 'Waiting for callback', 6 => 'Requeue', 7 => 'In progress with pending data' }
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#initialize(interface, id, async = false, &block) ⇒ Job
constructor
A new instance of Job.
- #reload_status! ⇒ Object
- #status ⇒ Object
- #when_complete(&block) ⇒ Object
Constructor Details
#initialize(interface, id, async = false, &block) ⇒ Job
Returns a new instance of Job.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mios/job.rb', line 34 def initialize(interface, id, async = false, &block) @interface = interface @id = id reload_status! if block_given? if async Thread.new do when_complete(&block) end else when_complete(&block) end end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
32 33 34 |
# File 'lib/mios/job.rb', line 32 def id @id end |
Instance Method Details
#reload_status! ⇒ Object
74 75 76 |
# File 'lib/mios/job.rb', line 74 def reload_status! @status = @interface.job_status(@id) end |
#status ⇒ Object
70 71 72 |
# File 'lib/mios/job.rb', line 70 def status @status || reload_status! end |
#when_complete(&block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mios/job.rb', line 50 def when_complete(&block) raise Error::JobTimeout if nonexistent? Timeout::timeout(20) do sleep_interval = 0.25 # If the job is still processing, wait a bit and try again while waiting? || in_progress? || waiting_for_callback? || in_progress_with_pending_data? do sleep(sleep_interval += 0.25) reload_status! end raise Error::JobError if error? raise Error::JobAborted if aborted? raise Error::JobRequeue if requeue? end yield rescue Timeout::Error $stderr.puts 'Timed out waiting for job status to become complete' raise Error::JobTimeout end |