> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/taskforcesh/bullmq/llms.txt
> Use this file to discover all available pages before exploring further.

# Job

> Represents a job in the queue with data, options, and state

## Overview

The Job class represents a job in the queue. Jobs are normally created implicitly when you add a job to the queue with `Queue.add()`, but a Job instance is also passed to the Worker's process function.

## Constructor

```typescript theme={null}
new Job(
  queue: MinimalQueue,
  name: string,
  data: any,
  opts?: JobsOptions,
  id?: string
)
```

<Note>
  Jobs are typically created using `Queue.add()` rather than instantiating directly.
</Note>

## Properties

### id

```typescript theme={null}
id?: string
```

The unique identifier of the job.

### name

```typescript theme={null}
name: string
```

The name of the job.

### data

```typescript theme={null}
data: any
```

The payload data for this job.

### opts

```typescript theme={null}
opts: JobsOptions
```

The options object for this job.

### progress

```typescript theme={null}
progress: number | object = 0
```

The progress a job has performed so far.

### returnvalue

```typescript theme={null}
returnvalue: any = null
```

The value returned by the processor when processing this job.

### stacktrace

```typescript theme={null}
stacktrace: string[] = null
```

Stacktrace for the error (for failed jobs).

### timestamp

```typescript theme={null}
timestamp: number
```

Timestamp when the job was created.

### attemptsMade

```typescript theme={null}
attemptsMade: number = 0
```

Number of attempts after the job has failed.

### attemptsStarted

```typescript theme={null}
attemptsStarted: number = 0
```

Number of times job has been moved to active state.

### delay

```typescript theme={null}
delay: number = 0
```

An amount of milliseconds to wait until this job can be processed.

### priority

```typescript theme={null}
priority: number = 0
```

Ranges from 0 (highest priority) to 2,097,152 (lowest priority).

### processedOn

```typescript theme={null}
processedOn?: number
```

Timestamp for when the job was processed.

### finishedOn

```typescript theme={null}
finishedOn?: number
```

Timestamp for when the job finished (completed or failed).

### failedReason

```typescript theme={null}
failedReason: string
```

Reason for failing.

## Static Methods

### create

Creates a new job and adds it to the queue.

```typescript theme={null}
static create<T, R, N>(
  queue: MinimalQueue,
  name: N,
  data: T,
  opts?: JobsOptions
): Promise<Job<T, R, N>>
```

### createBulk

Creates a bulk of jobs and adds them atomically to the queue.

```typescript theme={null}
static createBulk<T, R, N>(
  queue: MinimalQueue,
  jobs: Array<{ name: N; data: T; opts?: JobsOptions }>
): Promise<Job<T, R, N>[]>
```

### fromId

Fetches a Job from the queue by ID.

```typescript theme={null}
static fromId<T, R, N>(
  queue: MinimalQueue,
  jobId: string
): Promise<Job<T, R, N> | undefined>
```

## Methods

### updateProgress

Updates a job's progress.

```typescript theme={null}
updateProgress(progress: number | object): Promise<void>
```

<ParamField path="progress" type="number | object" required>
  Number or object to be saved as progress
</ParamField>

### updateData

Updates a job's data.

```typescript theme={null}
updateData(data: any): Promise<void>
```

<ParamField path="data" type="any" required>
  The data that will replace the current job's data
</ParamField>

### log

Logs one row of log data.

```typescript theme={null}
log(logRow: string): Promise<number>
```

<ParamField path="logRow" type="string" required>
  String with log data to be logged
</ParamField>

<ResponseField name="count" type="number">
  The total number of log entries for this job
</ResponseField>

### remove

Completely removes the job from the queue.

```typescript theme={null}
remove(opts?: { removeChildren?: boolean }): Promise<void>
```

<ParamField path="opts.removeChildren" type="boolean" default="true">
  Whether to remove child jobs
</ParamField>

### retry

Attempts to retry the job.

```typescript theme={null}
retry(state?: 'completed' | 'failed', opts?: RetryOptions): Promise<void>
```

<ParamField path="state" type="string" default="'failed'">
  The state from which to retry (completed or failed)
</ParamField>

<ParamField path="opts" type="RetryOptions">
  Retry options
</ParamField>

### promote

Promotes a delayed job so that it starts to be processed as soon as possible.

```typescript theme={null}
promote(): Promise<void>
```

### changeDelay

Changes the delay of a delayed job.

```typescript theme={null}
changeDelay(delay: number): Promise<void>
```

<ParamField path="delay" type="number" required>
  Milliseconds from now when the job should be processed
</ParamField>

### changePriority

Changes the priority of a job.

```typescript theme={null}
changePriority(opts: { priority?: number; lifo?: boolean }): Promise<void>
```

<ParamField path="opts.priority" type="number">
  New priority value
</ParamField>

<ParamField path="opts.lifo" type="boolean">
  Whether to add to the left (LIFO) or right (FIFO)
</ParamField>

### getState

Gets the current state of the job.

```typescript theme={null}
getState(): Promise<JobState | 'unknown'>
```

<ResponseField name="state" type="string">
  One of: 'completed', 'failed', 'delayed', 'active', 'waiting', 'waiting-children', 'unknown'
</ResponseField>

### isCompleted

Checks if the job has completed.

```typescript theme={null}
isCompleted(): Promise<boolean>
```

### isFailed

Checks if the job has failed.

```typescript theme={null}
isFailed(): Promise<boolean>
```

### isDelayed

Checks if the job is delayed.

```typescript theme={null}
isDelayed(): Promise<boolean>
```

### isActive

Checks if the job is active.

```typescript theme={null}
isActive(): Promise<boolean>
```

### isWaiting

Checks if the job is waiting.

```typescript theme={null}
isWaiting(): Promise<boolean>
```

### isWaitingChildren

Checks if the job is waiting for children.

```typescript theme={null}
isWaitingChildren(): Promise<boolean>
```

### getChildrenValues

Gets the result values of child jobs.

```typescript theme={null}
getChildrenValues<T>(): Promise<{ [jobKey: string]: T }>
```

### getDependencies

Gets children job keys if this job is a parent.

```typescript theme={null}
getDependencies(opts?: DependenciesOpts): Promise<{
  processed?: Record<string, any>;
  unprocessed?: string[];
  failed?: string[];
  ignored?: Record<string, any>;
}>
```

### getDependenciesCount

Gets children job counts if this job is a parent.

```typescript theme={null}
getDependenciesCount(opts?: {
  processed?: boolean;
  unprocessed?: boolean;
  failed?: boolean;
  ignored?: boolean;
}): Promise<{
  processed?: number;
  unprocessed?: number;
  failed?: number;
  ignored?: number;
}>
```

### waitUntilFinished

Returns a promise that resolves when the job has completed or rejects when failed.

```typescript theme={null}
waitUntilFinished(queueEvents: QueueEvents, ttl?: number): Promise<any>
```

<ParamField path="queueEvents" type="QueueEvents" required>
  Instance of QueueEvents to listen for completion
</ParamField>

<ParamField path="ttl" type="number">
  Time in milliseconds to wait before timing out
</ParamField>

### moveToCompleted

Moves a job to the completed state.

```typescript theme={null}
moveToCompleted(
  returnValue: any,
  token: string,
  fetchNext?: boolean
): Promise<void | any[]>
```

### moveToFailed

Moves a job to the failed state.

```typescript theme={null}
moveToFailed(
  err: Error,
  token: string,
  fetchNext?: boolean
): Promise<void | any[]>
```

### extendLock

Extends the lock for this job.

```typescript theme={null}
extendLock(token: string, duration: number): Promise<number>
```

<ParamField path="token" type="string" required>
  Unique token for the lock
</ParamField>

<ParamField path="duration" type="number" required>
  Lock duration in milliseconds
</ParamField>
