Class: Wesabe::Job
Instance Attribute Summary collapse
-
#created_at ⇒ Object
When this job was created.
-
#credential ⇒ Object
The credential that this job belongs to.
-
#id ⇒ Object
The globally unique identifier for this job.
-
#result ⇒ Object
The result of this job, which gives more specific information for “pending” and “failed” statuses.
-
#status ⇒ Object
The status of this job (pending|successful|failed).
Attributes inherited from BaseModel
Class Method Summary collapse
-
.from_xml(xml) ⇒ Wesabe::Job
Returns a
Wesabe::Job
generated from Wesabe’s API XML.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Determines whether this job is finished.
-
#failed? ⇒ Boolean
Determines whether this job failed.
-
#initialize {|job| ... } ⇒ Job
constructor
Initializes a
Wesabe::Job
and yields itself. - #inspect ⇒ Object
-
#pending? ⇒ Boolean
Determines whether this job is still running.
-
#reload ⇒ Wesabe::Job
Reloads this job from the server, useful when polling for updates.
-
#successful? ⇒ Boolean
Determines whether this job is successful.
Methods inherited from BaseModel
Methods included from Util
Constructor Details
#initialize {|job| ... } ⇒ Job
Initializes a Wesabe::Job
and yields itself.
18 19 20 |
# File 'lib/wesabe/job.rb', line 18 def initialize yield self if block_given? end |
Instance Attribute Details
#created_at ⇒ Object
When this job was created.
10 11 12 |
# File 'lib/wesabe/job.rb', line 10 def created_at @created_at end |
#credential ⇒ Object
The credential that this job belongs to.
12 13 14 |
# File 'lib/wesabe/job.rb', line 12 def credential @credential end |
#id ⇒ Object
The globally unique identifier for this job.
3 4 5 |
# File 'lib/wesabe/job.rb', line 3 def id @id end |
#result ⇒ Object
The result of this job, which gives more specific information for “pending” and “failed” statuses.
8 9 10 |
# File 'lib/wesabe/job.rb', line 8 def result @result end |
#status ⇒ Object
The status of this job (pending|successful|failed).
5 6 7 |
# File 'lib/wesabe/job.rb', line 5 def status @status end |
Class Method Details
.from_xml(xml) ⇒ Wesabe::Job
Returns a Wesabe::Job
generated from Wesabe’s API XML.
79 80 81 82 83 84 85 86 |
# File 'lib/wesabe/job.rb', line 79 def self.from_xml(xml) new do |job| job.id = xml.at('id').inner_text job.status = xml.at('status').inner_text job.result = xml.at('result').inner_text job.created_at = Time.parse(xml.at('created-at').inner_text) end end |
Instance Method Details
#complete? ⇒ Boolean
Determines whether this job is finished.
52 53 54 |
# File 'lib/wesabe/job.rb', line 52 def complete? !pending? end |
#failed? ⇒ Boolean
Determines whether this job failed.
68 69 70 |
# File 'lib/wesabe/job.rb', line 68 def failed? status == 'failed' end |
#inspect ⇒ Object
88 89 90 |
# File 'lib/wesabe/job.rb', line 88 def inspect inspect_these :id, :status, :result, :created_at end |
#pending? ⇒ Boolean
Determines whether this job is still running.
45 46 47 |
# File 'lib/wesabe/job.rb', line 45 def pending? status == 'pending' end |
#reload ⇒ Wesabe::Job
Reloads this job from the server, useful when polling for updates.
job = credential.start_job
until job.complete?
print '.'
job.reload
sleep 1
end
puts
puts "Job finished with status=#{job.status}, result=#{job.result}"
34 35 36 37 38 39 40 |
# File 'lib/wesabe/job.rb', line 34 def reload replace( Wesabe::Job.from_xml( Hpricot.XML( get(:url => "/credentials/#{credential.id}/jobs/#{id}.xml")))) return self end |
#successful? ⇒ Boolean
Determines whether this job is successful.
60 61 62 |
# File 'lib/wesabe/job.rb', line 60 def successful? status == 'successful' end |