@lancedb/lancedb • Docs
@lancedb/lancedb / Job
Class: Job<T>¶
A handle to an operation that may still be running.
The operation may already be complete when the handle is created.
The detail getters read what the handle last observed. Submitting an operation returns only a job id, so populating them eagerly would cost an extra round trip on every call:
- Job.refresh and Job.status fetch the whole record.
- Job.wait records the terminal state it establishes, but not the rest of the record.
- Registry details are null until one of those runs. Query handles report jobType "query" immediately.
Type Parameters¶
• T = void
Accessors¶
attempt¶
One-based attempt ordinal. Worker replacement does not increment it.
Returns¶
null | number
creationMs¶
When the job was created, in milliseconds since the epoch.
Returns¶
null | number
executionEpoch¶
Most recent execution's fencing token, when reported.
Returns¶
null | number
failure¶
Why the job failed, when it failed and the server reports a reason.
Returns¶
null | JobFailureInfo
id¶
Identifies the operation on the server that is running it.
Registry handles expose a registry job ID; query handles expose a connection-scoped SQL query UUID string. Local handles have no ID. Query handles report jobType "query". Their IDs are not registry IDs or durable resume tokens.
Returns¶
null | string
jobId¶
Identity of the selected attempt last observed by this handle.
For operation handles, refresh() or status() can select a different
attempt while id stays unchanged. Save this value after refreshing and
use it throughout paged diagnostics. Local IDs cannot be reopened on a server.
Returns¶
null | string
jobType¶
"query" immediately for SQL-backed handles; otherwise the cached server-reported job type. Null for in-process handles.
Returns¶
null | string
lifecycleState¶
Detailed state last observed; unknown values never establish success.
Returns¶
null | JobState
operationId¶
Root of the explicit retry lineage, when reported.
Returns¶
null | string
result¶
The job-type-specific terminal result. Null until the job succeeds, so a job that never terminates reports its progress through Job.events instead.
Returns¶
any
retryOf¶
Immediate predecessor attempt, when reported.
Returns¶
null | string
sourceTableVersion¶
Source snapshot pinned for this attempt, when reported.
Returns¶
null | number
spec¶
The job-type-specific specification it was submitted with.
Returns¶
any
state¶
The last observed lifecycle state, without contacting the backend.
Returns¶
null | string
Methods¶
cancel()¶
Request cancellation. Cancelling a finished operation is a no-op.
Returns¶
Promise<void>
captureProfile()¶
Request a profile of a running Enterprise Function worker session. Returns the accepted identity without waiting for recording to finish. Requires System Operate permission and server profiling support. The server pins the worker, Python session and execution epoch. One capture per job can be active. Captures add workload-dependent overhead.
GPU tracing requires initialized PyTorch CUDA/CUPTI. CPU sampling requires readable per-thread procfs and is unavailable in dedicated sandboxes.
Parameters¶
-
workerId:
string -
options:
FunctionProfileOptions={}
Returns¶
Promise<FunctionProfile>
Example¶
const profile = await job.captureProfile("worker-id", {
kind: "gpu", durationSeconds: 2,
});
await job.waitForProfile(profile.profileId, { timeoutMs: 60_000 });
await job.exportProfile(profile.profileId, "gpu.trace.json");
events()¶
This job's recorded lifecycle events.
Where the getters above report a terminal result only once the job reaches
one, events are written as the job runs and outlive the workers that
produced them. A distributed job records a claim/claim_complete pair
per unit of work, each carrying rows_processed, so a job that never
finishes still accounts for what it did.
The server caps results at 1000 rows by default and 10,000 at most, and
truncates without saying so, so pass limit for a job that emits an event
per fragment. filter is a SQL-like expression over the state,
updated_by, emitted_from, emitted_by, and claim_entity columns.
Parameters¶
- options?:
JobEventsOptions
Returns¶
Promise<Table<any>>
exportProfile()¶
Write a completed capture's JSON after successful retrieval. Open CPU exports in speedscope and GPU exports in Perfetto. GPU activity durations can overlap and are not utilization; Python operator attribution and GPU allocation stacks are excluded. Filesystem errors propagate to the caller.
Parameters¶
-
profileId:
string -
path:
string
Returns¶
Promise<void>
history()¶
Walk retained history one page at a time using the server's continuation.
Parameters¶
- options?:
JobEventsOptions
Returns¶
AsyncGenerator<Table<any>, any, unknown>
profileArtifact()¶
Retrieve a completed capture's actual JSON: speedscope for CPU, tracemalloc for Python allocations, or Chrome Trace Event JSON for GPU. Truncation flags are preserved. Retention is at most one hour and eight captures per job, until earlier scratch reclamation or archival. Permission, expired-artifact and unsupported-server errors propagate.
Parameters¶
- profileId:
string
Returns¶
Promise<Record<string, unknown>>
profileStatus()¶
Fetch capture identity and status, including retained lookup after refresh. Failed captures return status "failed" with the server's error reason. This never changes the parent job's cached state.
Parameters¶
- profileId:
string
Returns¶
Promise<FunctionProfile>
progress()¶
Fetch a structured progress snapshot.
Registry jobs include lifecycle and queue metadata even when their job type does not report counters. The returned object is forward-compatible with newer servers and job types. In-process operations return null.
Returns¶
Promise<null | JobProgress>
refresh()¶
Ask the backend for this job's current state, and for a server-side job its full record, then cache it for the getters above.
Returns¶
Promise<void>
retry()¶
Select this exact attempt's pinned successor. Requires backend support.
Returns¶
Promise<Job<T>>
status()¶
The current status, usually "running", "finished", "failed", or "cancelled". A Function refresh waiting for execution workers reports "waiting_for_capacity".
A point snapshot; unlike Job.wait it does not block or reject on a terminal failure state. Also refreshes the getters above.
Returns¶
Promise<string>
statusTyped()¶
Refresh and return the detailed lifecycle state.
Returns¶
Promise<JobState>
toString()¶
Every field the handle currently knows, one per line, with the JSON payloads indented -- a refresh job's spec and result are the point of printing it.
Returns¶
string
wait()¶
Wait until the operation reaches a terminal state.
The optional callback observes the same snapshots fetched by the backend
poller that drives completion; it does not start another poller. Without a
callback, this preserves the original wait behavior. The callback is a
synchronous observer: its return value is ignored and not awaited. If it
throws, the error is logged with console.warn and waiting continues; a
callback exception does not reject wait.
Pass an options object to set a client-side timeout. Expiry rejects with an
error and stops this wait, including pending status requests and backoff.
The operation continues; use the same handle to wait again. Registry jobs
can also be reopened with Connection.openJob; query IDs cannot.
Parameters¶
- optionsOrProgress?:
JobWaitOptions|JobProgressCallback
Returns¶
Promise<T>
Example¶
waitForProfile()¶
Wait for a capture with a configurable timeout and polling cadence. Defaults to 60 seconds with two seconds between requests. A timeout stops only this wait; the capture and Function refresh continue. A failed capture rejects with its server-reported reason. Keep its ID to wait again.
Parameters¶
-
profileId:
string -
options:
FunctionProfileWaitOptions={}
Returns¶
Promise<FunctionProfile>