Class: Quicopt::Job
- Inherits:
-
Object
- Object
- Quicopt::Job
- Defined in:
- lib/quicopt/client.rb
Overview
A handle to an asynchronous job. result polls until it finishes.
Instance Attribute Summary collapse
-
#client ⇒ Client
readonly
The client that submitted the job.
-
#job_id ⇒ String
readonly
The server-assigned job id.
Instance Method Summary collapse
-
#delete ⇒ nil
Delete the job and its stored blob, result and log on the server.
-
#initialize(client, job_id) ⇒ Job
constructor
A new instance of Job.
-
#inspect ⇒ String
The job id, tagged with the class.
-
#log ⇒ String
Fetch the job's log — the same framed view as
display, not a raw solver log. -
#result(wait: true, timeout: 120.0, poll: 0.5) ⇒ Result
Fetch the job's result, optionally polling until it is ready.
-
#status ⇒ Hash
Fetch the job's metadata and framed log tail.
Constructor Details
#initialize(client, job_id) ⇒ Job
Returns a new instance of Job.
449 450 451 452 |
# File 'lib/quicopt/client.rb', line 449 def initialize(client, job_id) @client = client @job_id = job_id end |
Instance Attribute Details
#client ⇒ Client (readonly)
Returns the client that submitted the job.
445 446 447 |
# File 'lib/quicopt/client.rb', line 445 def client @client end |
#job_id ⇒ String (readonly)
Returns the server-assigned job id.
447 448 449 |
# File 'lib/quicopt/client.rb', line 447 def job_id @job_id end |
Instance Method Details
#delete ⇒ nil
Delete the job and its stored blob, result and log on the server.
494 495 496 497 |
# File 'lib/quicopt/client.rb', line 494 def delete @client.request_raw("DELETE", "/v1/jobs/#{@job_id}") nil end |
#inspect ⇒ String
Returns the job id, tagged with the class.
500 501 502 |
# File 'lib/quicopt/client.rb', line 500 def inspect "#<Quicopt::Job #{@job_id}>" end |
#log ⇒ String
Fetch the job's log — the same framed view as display, not a raw solver
log.
487 488 489 |
# File 'lib/quicopt/client.rb', line 487 def log @client.request_raw("GET", "/v1/jobs/#{@job_id}/log") end |
#result(wait: true, timeout: 120.0, poll: 0.5) ⇒ Result
Fetch the job's result, optionally polling until it is ready.
471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/quicopt/client.rb', line 471 def result(wait: true, timeout: 120.0, poll: 0.5) deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout loop do return Result.from_json(@client.request("GET", "/v1/jobs/#{@job_id}/result")) rescue QuicoptError => e raise if !wait || e.reason != "not_done" raise if Process.clock_gettime(Process::CLOCK_MONOTONIC) > deadline sleep(poll) end end |
#status ⇒ Hash
Fetch the job's metadata and framed log tail.
458 459 460 |
# File 'lib/quicopt/client.rb', line 458 def status @client.request("GET", "/v1/jobs/#{@job_id}") end |