Class: Pho::Job
- Inherits:
-
Object
- Object
- Pho::Job
- Defined in:
- lib/pho/job.rb
Overview
A Platform Job
Instances of this class encapsulate all of the core metadata relating to a Platform Job. This includes not only the timing information but also the completion status, etc.
The class provides convenience methods for retrieving and parsing data about a specific Job from a platform store
Constant Summary collapse
- SUCCESS =
"http://schemas.talis.com/2006/bigfoot/configuration#success"
- ABORTED =
"http://schemas.talis.com/2006/bigfoot/configuration#aborted"
Instance Attribute Summary collapse
-
#actual_start_time ⇒ Object
Date-time that the job actually started.
-
#completion_message ⇒ Object
Completion message.
-
#completion_status ⇒ Object
URI indicating completion status of the job.
-
#created ⇒ Object
readonly
Date-time that the job was created.
-
#end_time ⇒ Object
Date time that the job actually completed.
-
#label ⇒ Object
readonly
Label associated with job.
-
#progress_updates ⇒ Object
An array of JobUpdate instances.
-
#snapshot_uri ⇒ Object
URI of snapshot to load.
-
#start_message ⇒ Object
Message recorded at the time the job started.
-
#start_time ⇒ Object
readonly
Date-time that the job will start.
-
#type ⇒ Object
readonly
Type of job.
-
#uri ⇒ Object
readonly
URI of the job.
Class Method Summary collapse
-
.parse(uri, xml) ⇒ Object
Parses job metadata returned from the platform as RDF/XML, creating a fully populated Job instance.
-
.read_from_store(uri, store) ⇒ Object
Read a job from a store.
Instance Method Summary collapse
-
#completed? ⇒ Boolean
Has the job completed?.
-
#initialize(uri, label, type, start_time, created = nil) ⇒ Job
constructor
Constructor.
-
#running? ⇒ Boolean
Is the job still running?.
-
#started? ⇒ Boolean
Has the job started?.
-
#successful? ⇒ Boolean
Was the job successful?.
Constructor Details
#initialize(uri, label, type, start_time, created = nil) ⇒ Job
Constructor. Used in the reading/parsing code
- uri
-
a unique identifier for the job
- label
-
a description of the job
- type
-
the type of the job, e.g. Pho::Jobs::RESTORE
- created
-
date-time the job was created in the system
- start_time
-
scheduled start time for the job
214 215 216 217 218 219 220 221 |
# File 'lib/pho/job.rb', line 214 def initialize(uri, label, type, start_time, created=nil) @uri = uri @label = label @type = type @created = created @start_time = start_time @progress_updates = Array.new end |
Instance Attribute Details
#actual_start_time ⇒ Object
Date-time that the job actually started
193 194 195 |
# File 'lib/pho/job.rb', line 193 def actual_start_time @actual_start_time end |
#completion_message ⇒ Object
Completion message
203 204 205 |
# File 'lib/pho/job.rb', line 203 def @completion_message end |
#completion_status ⇒ Object
URI indicating completion status of the job
201 202 203 |
# File 'lib/pho/job.rb', line 201 def completion_status @completion_status end |
#created ⇒ Object (readonly)
Date-time that the job was created
189 190 191 |
# File 'lib/pho/job.rb', line 189 def created @created end |
#end_time ⇒ Object
Date time that the job actually completed
205 206 207 |
# File 'lib/pho/job.rb', line 205 def end_time @end_time end |
#label ⇒ Object (readonly)
Label associated with job
185 186 187 |
# File 'lib/pho/job.rb', line 185 def label @label end |
#progress_updates ⇒ Object
An array of JobUpdate instances. May be empty if no updates have been logged
199 200 201 |
# File 'lib/pho/job.rb', line 199 def progress_updates @progress_updates end |
#snapshot_uri ⇒ Object
URI of snapshot to load. (For RestoreJob only)
195 196 197 |
# File 'lib/pho/job.rb', line 195 def snapshot_uri @snapshot_uri end |
#start_message ⇒ Object
Message recorded at the time the job started
197 198 199 |
# File 'lib/pho/job.rb', line 197 def @start_message end |
#start_time ⇒ Object (readonly)
Date-time that the job will start
191 192 193 |
# File 'lib/pho/job.rb', line 191 def start_time @start_time end |
#type ⇒ Object (readonly)
Type of job
187 188 189 |
# File 'lib/pho/job.rb', line 187 def type @type end |
#uri ⇒ Object (readonly)
URI of the job
183 184 185 |
# File 'lib/pho/job.rb', line 183 def uri @uri end |
Class Method Details
.parse(uri, xml) ⇒ Object
Parses job metadata returned from the platform as RDF/XML, creating a fully populated Job instance
- uri
-
uri of the job to be parsed
- xml
-
the RDF/XML text to be parsed
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/pho/job.rb', line 241 def Job.parse(uri, xml) doc = REXML::Document.new(xml) root = doc.root #job_el = REXML::XPath.first(root, "rdf:Description[rdf:type]", Pho::Namespaces::MAPPING ) job_el = REXML::XPath.first(root, "//*[@rdf:about='#{uri}']", Pho::Namespaces::MAPPING ) uri = job_el.attributes["rdf:about"] label = REXML::XPath.first(job_el, "rdfs:label", Pho::Namespaces::MAPPING ).text type_el = REXML::XPath.first(job_el, "rdf:type", Pho::Namespaces::MAPPING ) type = type_el.attributes["rdf:resource"] created = REXML::XPath.first(job_el, "dcterms:created", Pho::Namespaces::MAPPING ).text start_time = REXML::XPath.first(job_el, "bf:startTime", Pho::Namespaces::MAPPING ).text job = Job.new(uri, label, type, start_time, created) if type == Pho::Jobs::RESTORE with_first(job_el, "bf:snapshotUri") do |uri| job.snapshot_uri = uri.attributes["rdf:resource"] end end with_first(job_el, "bf:actualStartTime") do |el| job.actual_start_time = el.text end with_first(job_el, "bf:startMessage") do |el| job. = el.text end with_first(job_el, "bf:completionMessage") do |el| job. = el.text end with_first(job_el, "bf:endTime") do |el| job.end_time = el.text end with_first(job_el, "bf:completionStatus") do |el| job.completion_status = el.attributes["rdf:resource"] end with_each(job_el, "bf:progressUpdate") do |el| update = JobUpdate.new with_first(el, "bf:progressUpdateMessage") do |msg| update. = msg.text end with_first(el, "bf:progressUpdateTime") do |time| update.time = time.text end job.progress_updates << update end return job end |
.read_from_store(uri, store) ⇒ Object
Read a job from a store
- uri
-
uri of the job to read
- store
-
store from which the job will be read
227 228 229 230 231 232 233 234 |
# File 'lib/pho/job.rb', line 227 def Job.read_from_store(uri, store) resp = store.get_job(uri) if resp.status != 200 raise "Unable to read job from store. Response code was #{resp.status}" end return parse(uri, resp.content) end |
Instance Method Details
#completed? ⇒ Boolean
Has the job completed?
304 305 306 |
# File 'lib/pho/job.rb', line 304 def completed? return @completion_status != nil end |
#running? ⇒ Boolean
Is the job still running?
314 315 316 |
# File 'lib/pho/job.rb', line 314 def running? return started? && !completed? end |
#started? ⇒ Boolean
Has the job started?
299 300 301 |
# File 'lib/pho/job.rb', line 299 def started? return @actual_start_time != nil end |