api-swift / Sources / IrdAPI / Flows / JobsFlow.swift
93 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import Foundation

extension JobsAPI {
    /// Enqueue → poll `GET /jobs/{id}` until it settles → fetch the result. A `failed`
    /// job throws `IrdError.jobFailed`; a deadline throws `.timeout` carrying the last job.
    public func run(_ spec: JobSpec, options: PollOptions = .jobs) async throws -> JobResult {
        let queued = try await enqueue(body: spec).job
        let job = try await pollUntil(options, clock: client.configuration.clock,
                                      step: { try await get(id: queued.id).job },
                                      done: { $0.status == .succeeded || $0.status == .failed })
        if job.status == .failed { throw IrdError.jobFailed(job) }
        return try await getResult(id: job.id)
    }
}

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/api-swift.git