Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions apps/docs/content/docs/api/job-queue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,130 @@ cancelJob(jobId: number): Promise<void>

Cancels a job given its ID.

### editJob

```ts
editJob(jobId: number, updates: EditJobOptions): Promise<void>
```

Edits a pending job given its ID. Only works for jobs with status 'pending'. Silently fails for other statuses (processing, completed, failed, cancelled).

#### EditJobOptions

```ts
interface EditJobOptions {
payload?: any;
maxAttempts?: number;
priority?: number;
runAt?: Date | null;
timeoutMs?: number;
tags?: string[];
}
```

All fields are optional - only provided fields will be updated. Note that `jobType` cannot be changed.

#### Example

```ts
// Edit a pending job's payload and priority
await jobQueue.editJob(jobId, {
payload: { to: 'newemail@example.com', subject: 'Updated' },
priority: 10,
});

// Edit only the scheduled run time
await jobQueue.editJob(jobId, {
runAt: new Date(Date.now() + 60000), // Run in 1 minute
});

// Edit multiple fields at once
await jobQueue.editJob(jobId, {
payload: { to: 'updated@example.com' },
priority: 5,
maxAttempts: 10,
timeoutMs: 30000,
tags: ['urgent', 'priority'],
});
```

### editAllPendingJobs

```ts
editAllPendingJobs(
filters?: {
jobType?: string;
priority?: number;
runAt?: Date | { gt?: Date; gte?: Date; lt?: Date; lte?: Date; eq?: Date };
tags?: { values: string[]; mode?: 'all' | 'any' | 'none' | 'exact' };
},
updates: EditJobOptions
): Promise<number>
```

Edits all pending jobs that match the filters. Only works for jobs with status 'pending'. Non-pending jobs are not affected. Returns the number of jobs that were edited.

#### Parameters

- `filters` (optional): Filters to select which jobs to edit. If not provided, all pending jobs are edited.
- `jobType`: Filter by job type
- `priority`: Filter by priority
- `runAt`: Filter by scheduled run time (supports `gt`, `gte`, `lt`, `lte`, `eq` operators or exact Date match)
- `tags`: Filter by tags with mode ('all', 'any', 'none', 'exact')
- `updates`: The fields to update (same as `EditJobOptions`). All fields are optional - only provided fields will be updated.

#### Returns

The number of jobs that were successfully edited.

#### Examples

```ts
// Edit all pending jobs
const editedCount = await jobQueue.editAllPendingJobs(undefined, {
priority: 10,
});

// Edit all pending email jobs
const editedCount = await jobQueue.editAllPendingJobs(
{ jobType: 'email' },
{
priority: 5,
},
);

// Edit all pending jobs with 'urgent' tag
const editedCount = await jobQueue.editAllPendingJobs(
{ tags: { values: ['urgent'], mode: 'any' } },
{
priority: 10,
maxAttempts: 5,
},
);

// Edit all pending jobs scheduled in the future
const editedCount = await jobQueue.editAllPendingJobs(
{ runAt: { gte: new Date() } },
{
priority: 10,
},
);

// Edit with combined filters
const editedCount = await jobQueue.editAllPendingJobs(
{
jobType: 'email',
tags: { values: ['urgent'], mode: 'any' },
},
{
priority: 10,
maxAttempts: 5,
},
);
```

**Note:** Only pending jobs are edited. Jobs with other statuses (processing, completed, failed, cancelled) are not affected. Edit events are recorded for each affected job, just like single job edits.

### cancelAllUpcomingJobs

```ts
Expand Down Expand Up @@ -209,6 +333,7 @@ enum JobEventType {
Failed = 'failed',
Cancelled = 'cancelled',
Retried = 'retried',
Edited = 'edited',
}
```

Expand Down
Loading