Skip to content

CaptureJobModel

Defined in: packages/core/src/models/capture-job.ts:50

Data operations of the database queue. Every write is an unconditional update by id or an insert; the only atomic primitive is the unique-key insert of an attempt row (claim), which is what fences concurrent claimers on every supported database.

new CaptureJobModel(db, tables?): CaptureJobModel

Defined in: packages/core/src/models/capture-job.ts:55

DatabaseAdapter

CaptureJobTables

CaptureJobModel

attempts(jobId): Promise<CaptureJobRow[]>

Defined in: packages/core/src/models/capture-job.ts:219

Attempt rows of a job, by attempt number.

string

Promise<CaptureJobRow[]>


claim(input, now): Promise<boolean>

Defined in: packages/core/src/models/capture-job.ts:96

Claim attempt attempt of a job by inserting its row <jobId>:<attempt>. Exactly one caller succeeds on every database; the others hit the primary key, which this reports as false (told apart from real failures by re-reading the row, as CaptureShardModel.claimFinalize).

AttemptClaim

string

Promise<boolean>


clearVisibility(id, now): Promise<void>

Defined in: packages/core/src/models/capture-job.ts:148

Take a row out of the poll’s index range without changing its status.

string

string

Promise<void>


create(input, now): Promise<CaptureJobRow>

Defined in: packages/core/src/models/capture-job.ts:66

Insert a queued job row.

NewCaptureJob

string

Promise<CaptureJobRow>


defer(id, visibleAt, now): Promise<void>

Defined in: packages/core/src/models/capture-job.ts:143

Move a row’s visibility time (and nothing else).

string

string

string

Promise<void>


expiredAttempt(attemptId, now): Promise<CaptureJobRow | null>

Defined in: packages/core/src/models/capture-job.ts:130

The attempt row attemptId if it is running with a lease that passed by now, else null.

string

string

Promise<CaptureJobRow | null>


finishAttempt(attemptId, status, now, error?): Promise<void>

Defined in: packages/core/src/models/capture-job.ts:153

End an attempt row: done, failed (with its error) or expired (taken over).

string

"failed" | "done" | "expired"

string

string | null = null

Promise<void>


finishJob(jobId, status, now, error?): Promise<void>

Defined in: packages/core/src/models/capture-job.ts:169

End a job row for good.

string

"failed" | "cancelled" | "done"

string

string | null = null

Promise<void>


flagCancel(id, now): Promise<void>

Defined in: packages/core/src/models/capture-job.ts:195

Flag a row as cancel-requested; the flag is never cleared.

string

string

Promise<void>


get(id): Promise<CaptureJobRow | null>

Defined in: packages/core/src/models/capture-job.ts:61

string

Promise<CaptureJobRow | null>


latestForBuild(buildId, kinds): Promise<CaptureJobRow | null>

Defined in: packages/core/src/models/capture-job.ts:208

The build’s own (non-shard) job of kinds most recently queued, or null.

string

readonly CaptureJobKind[]

Promise<CaptureJobRow | null>


listActive(kinds): Promise<CaptureJobRow[]>

Defined in: packages/core/src/models/capture-job.ts:227

Job rows of kinds that are queued or running, oldest first.

readonly CaptureJobKind[]

Promise<CaptureJobRow[]>


listForBuild(buildId): Promise<CaptureJobRow[]>

Defined in: packages/core/src/models/capture-job.ts:200

Job rows of a build (its own job and its shard jobs), oldest first.

string

Promise<CaptureJobRow[]>


listRecent(kinds, limit): Promise<CaptureJobRow[]>

Defined in: packages/core/src/models/capture-job.ts:239

The newest job rows of kinds, newest first.

readonly CaptureJobKind[]

number

Promise<CaptureJobRow[]>


markRunning(jobId, attempt, now): Promise<void>

Defined in: packages/core/src/models/capture-job.ts:110

The claim won: the job row records the running attempt and leaves the poll’s index range.

string

number

string

Promise<void>


nextCandidate(kinds, now): Promise<CaptureJobRow | null>

Defined in: packages/core/src/models/capture-job.ts:75

The poll probe: the oldest row of kinds that may be claimed at now. One indexed range query on (kind, visible_at, status), limit 1; only candidates have a visibleAt, so an empty queue reads no rows and a busy one reads one.

readonly CaptureJobKind[]

string

Promise<CaptureJobRow | null>


purgeFinished(before): Promise<number>

Defined in: packages/core/src/models/capture-job.ts:252

Retention: delete finished jobs created before before, with their attempt rows. Returns the number of jobs removed. Running and queued jobs are never touched.

string

Promise<number>


removeForBuild(buildId): Promise<number>

Defined in: packages/core/src/models/capture-job.ts:273

A build was removed: delete every capture_jobs row that points at it (job and attempt rows, whatever their status). There is no foreign key, so retention does this by hand. Returns the number of rows removed.

string

Promise<number>


renew(attemptId, leaseUntil, now): Promise<CaptureJobRow | null>

Defined in: packages/core/src/models/capture-job.ts:121

Push an attempt’s lease out. Returns the row (null if gone) so the caller sees cancel or expiry.

string

string

string

Promise<CaptureJobRow | null>


requeue(jobId, visibleAt, error, now): Promise<void>

Defined in: packages/core/src/models/capture-job.ts:180

Put a job back on the queue, claimable from visibleAt, remembering why the attempt failed.

string

string

string | null

string

Promise<void>