Skip to content

Commit 987cf84

Browse files
authored
feat!: remove deprecated jobs queue depth and runHooks options (#16414)
**BREAKING:** The deprecated `jobs.depth` and `jobs.runHooks` config options have been removed. Job operations now always use direct database calls with depth `0`. If you relied on either option, remove it from your `jobs` config; if you depended on collection hooks running for jobs, migrate that logic out of hooks. The `jobsCollectionOverrides` warning that detected extra hooks and prompted users to set `runHooks` has also been removed. --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1214349495376496
1 parent ede59ac commit 987cf84

7 files changed

Lines changed: 22 additions & 127 deletions

File tree

packages/payload/src/config/sanitize.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,6 @@ export const sanitizeConfig = async (incomingConfig: Config): Promise<SanitizedC
411411
defaultJobsCollection = config.jobs.jobsCollectionOverrides({
412412
defaultJobsCollection,
413413
})
414-
415-
const hooks = defaultJobsCollection?.hooks
416-
// @todo - delete this check in 4.0
417-
if (hooks && config?.jobs?.runHooks !== true) {
418-
for (const [hookKey, hook] of Object.entries(hooks)) {
419-
const defaultAmount = hookKey === 'afterRead' || hookKey === 'beforeChange' ? 1 : 0
420-
if (hook.length > defaultAmount) {
421-
// eslint-disable-next-line no-console
422-
console.warn(
423-
`The jobsCollectionOverrides function is returning a collection with an additional ${hookKey} hook defined. These hooks will not run unless the jobs.runHooks option is set to true. Setting this option to true will negatively impact performance.`,
424-
)
425-
break
426-
}
427-
}
428-
}
429414
}
430415
const sanitizedJobsCollection = await sanitizeCollection(
431416
config as unknown as Config,

packages/payload/src/queues/config/types/index.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,6 @@ export type JobsConfig = {
135135
* Determine whether or not to delete a job after it has successfully completed.
136136
*/
137137
deleteJobOnComplete?: boolean
138-
/**
139-
* Specify depth for retrieving jobs from the queue.
140-
* This should be as low as possible in order for job retrieval
141-
* to be as efficient as possible. Setting it to anything higher than
142-
* 0 will drastically affect performance, as less efficient database
143-
* queries will be used.
144-
*
145-
* @default 0
146-
* @deprecated - this will be removed in 4.0
147-
*/
148-
depth?: number
149138
/**
150139
* Enable concurrency controls for workflows and tasks.
151140
* When enabled, adds a `concurrencyKey` field to the jobs collection schema.
@@ -179,16 +168,6 @@ export type JobsConfig = {
179168
}
180169
}
181170
| Sort
182-
/**
183-
* By default, the job system uses direct database calls for optimal performance.
184-
* If you added custom hooks to your jobs collection, you can set this to true to
185-
* use the standard Payload API for all job operations. This is discouraged, as it will
186-
* drastically affect performance.
187-
*
188-
* @default false
189-
* @deprecated - this will be removed in 4.0
190-
*/
191-
runHooks?: boolean
192171
/**
193172
* A function that will be executed before Payload picks up jobs which are configured by the `jobs.autorun` function.
194173
* If this function returns true, jobs will be queried and picked up. If it returns false, jobs will not be run.

packages/payload/src/queues/localAPI.ts

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -193,32 +193,17 @@ export const getJobsLocalAPI = (payload: Payload) => ({
193193

194194
// If supersedes is enabled, delete older pending jobs with the same key
195195
if (supersedes) {
196-
if (payload.config.jobs.runHooks) {
197-
await payload.delete({
198-
collection: jobsCollectionSlug,
199-
depth: 0,
200-
disableTransaction: true,
201-
where: {
202-
and: [
203-
{ concurrencyKey: { equals: concurrencyKey } },
204-
{ processing: { equals: false } },
205-
{ completedAt: { exists: false } },
206-
],
207-
},
208-
})
209-
} else {
210-
await payload.db.deleteMany({
211-
collection: jobsCollectionSlug,
212-
req,
213-
where: {
214-
and: [
215-
{ concurrencyKey: { equals: concurrencyKey } },
216-
{ processing: { equals: false } },
217-
{ completedAt: { exists: false } },
218-
],
219-
},
220-
})
221-
}
196+
await payload.db.deleteMany({
197+
collection: jobsCollectionSlug,
198+
req,
199+
where: {
200+
and: [
201+
{ concurrencyKey: { equals: concurrencyKey } },
202+
{ processing: { equals: false } },
203+
{ completedAt: { exists: false } },
204+
],
205+
},
206+
})
222207
}
223208
}
224209
}
@@ -227,24 +212,14 @@ export const getJobsLocalAPI = (payload: Payload) => ({
227212
? Job<TTaskOrWorkflowSlug>
228213
: RunningJobFromTask<TTaskOrWorkflowSlug> // Type assertion is still needed here
229214

230-
if (payload?.config?.jobs?.depth || payload?.config?.jobs?.runHooks) {
231-
return (await payload.create({
215+
return jobAfterRead({
216+
config: payload.config,
217+
doc: await payload.db.create({
232218
collection: jobsCollectionSlug,
233219
data,
234-
depth: payload.config.jobs.depth ?? 0,
235-
overrideAccess,
236220
req,
237-
})) as ReturnType
238-
} else {
239-
return jobAfterRead({
240-
config: payload.config,
241-
doc: await payload.db.create({
242-
collection: jobsCollectionSlug,
243-
data,
244-
req,
245-
}),
246-
}) as unknown as ReturnType
247-
}
221+
}),
222+
}) as unknown as ReturnType
248223
},
249224

250225
run: async (args?: {
@@ -406,8 +381,6 @@ export const getJobsLocalAPI = (payload: Payload) => ({
406381
processing: false,
407382
waitUntil: null,
408383
},
409-
depth: 0, // No depth, since we're not returning
410-
disableTransaction: true,
411384
req,
412385
returning: false,
413386
where: { and },
@@ -452,8 +425,6 @@ export const getJobsLocalAPI = (payload: Payload) => ({
452425
processing: false,
453426
waitUntil: null,
454427
},
455-
depth: 0, // No depth, since we're not returning
456-
disableTransaction: true,
457428
req,
458429
returning: false,
459430
})

packages/payload/src/queues/operations/runJobs/index.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ export const runJobs = async (args: RunJobsArgs): Promise<RunJobsResult> => {
204204
data: {
205205
processing: true,
206206
},
207-
depth: jobsConfig.depth,
208-
disableTransaction: true,
209207
req,
210208
returning: true,
211209
})
@@ -237,8 +235,6 @@ export const runJobs = async (args: RunJobsArgs): Promise<RunJobsResult> => {
237235
data: {
238236
processing: true,
239237
},
240-
depth: jobsConfig.depth,
241-
disableTransaction: true,
242238
limit,
243239
req,
244240
returning: true,
@@ -285,7 +281,6 @@ export const runJobs = async (args: RunJobsArgs): Promise<RunJobsResult> => {
285281
const releaseIds = jobsToRelease.map((job) => job.id)
286282
await updateJobs({
287283
data: { processing: false },
288-
disableTransaction: true,
289284
req,
290285
returning: false,
291286
where: { id: { in: releaseIds } },
@@ -449,8 +444,6 @@ export const runJobs = async (args: RunJobsArgs): Promise<RunJobsResult> => {
449444
processing: false,
450445
waitUntil: null,
451446
},
452-
depth: 0,
453-
disableTransaction: true,
454447
req,
455448
returning: false,
456449
})
@@ -485,19 +478,10 @@ export const runJobs = async (args: RunJobsArgs): Promise<RunJobsResult> => {
485478

486479
if (jobsConfig.deleteJobOnComplete && successfullyCompletedJobs.length) {
487480
try {
488-
if (jobsConfig.runHooks) {
489-
await payload.delete({
490-
collection: jobsCollectionSlug,
491-
depth: 0, // can be 0 since we're not returning anything
492-
disableTransaction: true,
493-
where: { id: { in: successfullyCompletedJobs } },
494-
})
495-
} else {
496-
await payload.db.deleteMany({
497-
collection: jobsCollectionSlug,
498-
where: { id: { in: successfullyCompletedJobs } },
499-
})
500-
}
481+
await payload.db.deleteMany({
482+
collection: jobsCollectionSlug,
483+
where: { id: { in: successfullyCompletedJobs } },
484+
})
501485
} catch (err) {
502486
if (!silent || (typeof silent === 'object' && !silent.error)) {
503487
payload.logger.error({

packages/payload/src/queues/operations/runJobs/runJob/getUpdateJobFunction.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export function getUpdateJobFunction(job: Job, req: PayloadRequest): UpdateJobFu
1616
const updatedJob = await updateJob({
1717
id: job.id,
1818
data: jobData,
19-
depth: req.payload.config.jobs.depth,
20-
disableTransaction: true,
2119
req,
2220
})
2321

packages/payload/src/queues/utilities/updateJob.ts

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import type { ManyOptions } from '../../collections/operations/local/update.js'
21
import type { UpdateJobsArgs } from '../../database/types.js'
32
import type { Job } from '../../index.js'
43
import type { PayloadRequest, Sort, Where } from '../../types/index.js'
54

6-
import { jobAfterRead, jobsCollectionSlug } from '../config/collection.js'
5+
import { jobAfterRead } from '../config/collection.js'
76
import { getCurrentDate } from './getCurrentDate.js'
87

98
type BaseArgs = {
109
data: Partial<Job>
11-
depth?: number
12-
disableTransaction?: boolean
1310
limit?: number
1411
req: PayloadRequest
1512
returning?: boolean
@@ -49,8 +46,6 @@ export async function updateJob(args: ArgsByID & BaseArgs) {
4946
export async function updateJobs({
5047
id,
5148
data,
52-
depth,
53-
disableTransaction,
5449
limit: limitArg,
5550
req,
5651
returning,
@@ -60,23 +55,6 @@ export async function updateJobs({
6055
const limit = id ? 1 : limitArg
6156
const where = id ? { id: { equals: id } } : whereArg
6257

63-
if (depth || req.payload.config?.jobs?.runHooks) {
64-
const result = await req.payload.update({
65-
id,
66-
collection: jobsCollectionSlug,
67-
data,
68-
depth,
69-
disableTransaction,
70-
limit,
71-
req,
72-
where,
73-
} as ManyOptions<any, any>)
74-
if (returning === false || !result) {
75-
return null
76-
}
77-
return result.docs as Job[]
78-
}
79-
8058
const jobReq = {
8159
transactionID:
8260
req.payload.db.name !== 'mongoose'

test/queues/int.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from
1414

1515
import type { NextRESTClient } from '../__helpers/shared/NextRESTClient.js'
1616

17-
import { devUser } from '../credentials.js'
1817
import { initPayloadInt } from '../__helpers/shared/initPayloadInt.js'
18+
import { devUser } from '../credentials.js'
1919
import { clearAndSeedEverything } from './seed.js'
2020
import { waitUntilAutorunIsDone } from './utilities.js'
2121

0 commit comments

Comments
 (0)