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.
450 451 452 453 |
# File 'lib/quicopt/client.rb', line 450 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.
446 447 448 |
# File 'lib/quicopt/client.rb', line 446 def client @client end |
#job_id ⇒ String (readonly)
Returns the server-assigned job id.
448 449 450 |
# File 'lib/quicopt/client.rb', line 448 def job_id @job_id end |
Instance Method Details
#delete ⇒ nil
Delete the job and its stored blob, result and log on the server.
495 496 497 498 |
# File 'lib/quicopt/client.rb', line 495 def delete @client.request_raw("DELETE", "/v1/jobs/#{@job_id}") nil end |
#inspect ⇒ String
Returns the job id, tagged with the class.
501 502 503 |
# File 'lib/quicopt/client.rb', line 501 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.
488 489 490 |
# File 'lib/quicopt/client.rb', line 488 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.
472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/quicopt/client.rb', line 472 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.
459 460 461 |
# File 'lib/quicopt/client.rb', line 459 def status @client.request("GET", "/v1/jobs/#{@job_id}") end |