payload 3.80.0-internal.cee0ccf → 3.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/endpoints/forgotPassword.d.ts.map +1 -1
- package/dist/auth/endpoints/forgotPassword.js +0 -2
- package/dist/auth/endpoints/forgotPassword.js.map +1 -1
- package/dist/auth/extractJWT.d.ts.map +1 -1
- package/dist/auth/extractJWT.js +18 -4
- package/dist/auth/extractJWT.js.map +1 -1
- package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
- package/dist/auth/operations/forgotPassword.js +5 -4
- package/dist/auth/operations/forgotPassword.js.map +1 -1
- package/dist/auth/operations/me.js +5 -5
- package/dist/auth/operations/me.js.map +1 -1
- package/dist/auth/sendVerificationEmail.d.ts.map +1 -1
- package/dist/auth/sendVerificationEmail.js +5 -4
- package/dist/auth/sendVerificationEmail.js.map +1 -1
- package/dist/collections/operations/update.js +1 -1
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/utilities/update.d.ts.map +1 -1
- package/dist/collections/operations/utilities/update.js +2 -1
- package/dist/collections/operations/utilities/update.js.map +1 -1
- package/dist/config/orderable/index.d.ts +2 -2
- package/dist/config/orderable/index.d.ts.map +1 -1
- package/dist/config/orderable/index.js +60 -34
- package/dist/config/orderable/index.js.map +1 -1
- package/dist/config/orderable/utils/buildJoinScopeWhere.d.ts +10 -0
- package/dist/config/orderable/utils/buildJoinScopeWhere.d.ts.map +1 -0
- package/dist/config/orderable/utils/buildJoinScopeWhere.js +43 -0
- package/dist/config/orderable/utils/buildJoinScopeWhere.js.map +1 -0
- package/dist/config/orderable/utils/getJoinScopeContext.d.ts +16 -0
- package/dist/config/orderable/utils/getJoinScopeContext.d.ts.map +1 -0
- package/dist/config/orderable/utils/getJoinScopeContext.js +42 -0
- package/dist/config/orderable/utils/getJoinScopeContext.js.map +1 -0
- package/dist/config/orderable/utils/getJoinScopeWhereFromDocData.d.ts +12 -0
- package/dist/config/orderable/utils/getJoinScopeWhereFromDocData.d.ts.map +1 -0
- package/dist/config/orderable/utils/getJoinScopeWhereFromDocData.js +18 -0
- package/dist/config/orderable/utils/getJoinScopeWhereFromDocData.js.map +1 -0
- package/dist/config/orderable/utils/getValueAtPath.d.ts +5 -0
- package/dist/config/orderable/utils/getValueAtPath.d.ts.map +1 -0
- package/dist/config/orderable/utils/getValueAtPath.js +18 -0
- package/dist/config/orderable/utils/getValueAtPath.js.map +1 -0
- package/dist/config/orderable/utils/resolvePendingTargetKey.d.ts +13 -0
- package/dist/config/orderable/utils/resolvePendingTargetKey.d.ts.map +1 -0
- package/dist/config/orderable/utils/resolvePendingTargetKey.js +24 -0
- package/dist/config/orderable/utils/resolvePendingTargetKey.js.map +1 -0
- package/dist/config/types.d.ts +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/getLocalizedPaths.d.ts.map +1 -1
- package/dist/database/getLocalizedPaths.js +2 -1
- package/dist/database/getLocalizedPaths.js.map +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js +1 -1
- package/dist/database/queryValidation/validateQueryPaths.js.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.d.ts.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.js +2 -1
- package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
- package/dist/database/sanitizeJoinQuery.d.ts.map +1 -1
- package/dist/database/sanitizeJoinQuery.js +6 -0
- package/dist/database/sanitizeJoinQuery.js.map +1 -1
- package/dist/database/types.d.ts +0 -1
- package/dist/database/types.d.ts.map +1 -1
- package/dist/database/types.js.map +1 -1
- package/dist/exports/shared.d.ts +1 -0
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +1 -0
- package/dist/exports/shared.js.map +1 -1
- package/dist/fields/baseFields/slug/index.d.ts +7 -0
- package/dist/fields/baseFields/slug/index.d.ts.map +1 -1
- package/dist/fields/baseFields/slug/index.js +2 -2
- package/dist/fields/baseFields/slug/index.js.map +1 -1
- package/dist/fields/validations.js +1 -1
- package/dist/fields/validations.js.map +1 -1
- package/dist/fields/validations.spec.js +25 -0
- package/dist/fields/validations.spec.js.map +1 -1
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js +2 -1
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/index.bundled.d.ts +16 -13
- package/dist/index.d.ts +1 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -10
- package/dist/index.js.map +1 -1
- package/dist/queues/localAPI.d.ts +0 -1
- package/dist/queues/localAPI.d.ts.map +1 -1
- package/dist/queues/localAPI.js +0 -4
- package/dist/queues/localAPI.js.map +1 -1
- package/dist/queues/operations/runJobs/index.d.ts +0 -1
- package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/index.js +1 -96
- package/dist/queues/operations/runJobs/index.js.map +1 -1
- package/dist/queues/utilities/updateJob.d.ts +1 -2
- package/dist/queues/utilities/updateJob.d.ts.map +1 -1
- package/dist/queues/utilities/updateJob.js +31 -92
- package/dist/queues/utilities/updateJob.js.map +1 -1
- package/dist/types/constants.d.ts +5 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/constants.js +4 -0
- package/dist/types/constants.js.map +1 -1
- package/dist/uploads/endpoints/getFile.d.ts.map +1 -1
- package/dist/uploads/endpoints/getFile.js +7 -1
- package/dist/uploads/endpoints/getFile.js.map +1 -1
- package/dist/uploads/endpoints/getFileFromURL.d.ts.map +1 -1
- package/dist/uploads/endpoints/getFileFromURL.js +67 -28
- package/dist/uploads/endpoints/getFileFromURL.js.map +1 -1
- package/dist/uploads/getExternalFile.d.ts.map +1 -1
- package/dist/uploads/getExternalFile.js +3 -0
- package/dist/uploads/getExternalFile.js.map +1 -1
- package/dist/uploads/safeFetch.d.ts +1 -1
- package/dist/uploads/safeFetch.d.ts.map +1 -1
- package/dist/uploads/safeFetch.js.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.js +7 -1
- package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts +7 -3
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +23 -33
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/configToJSONSchema.spec.js +75 -1
- package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
- package/dist/utilities/getRequestOrigin.d.ts +10 -0
- package/dist/utilities/getRequestOrigin.d.ts.map +1 -0
- package/dist/utilities/getRequestOrigin.js +50 -0
- package/dist/utilities/getRequestOrigin.js.map +1 -0
- package/dist/utilities/getRequestOrigin.spec.js +151 -0
- package/dist/utilities/getRequestOrigin.spec.js.map +1 -0
- package/dist/utilities/sanitizeUrl.d.ts +7 -0
- package/dist/utilities/sanitizeUrl.d.ts.map +1 -0
- package/dist/utilities/sanitizeUrl.js +28 -0
- package/dist/utilities/sanitizeUrl.js.map +1 -0
- package/dist/versions/saveVersion.d.ts +1 -0
- package/dist/versions/saveVersion.d.ts.map +1 -1
- package/dist/versions/saveVersion.js +16 -66
- package/dist/versions/saveVersion.js.map +1 -1
- package/dist/versions/updateLatestVersion.d.ts +24 -0
- package/dist/versions/updateLatestVersion.d.ts.map +1 -0
- package/dist/versions/updateLatestVersion.js +64 -0
- package/dist/versions/updateLatestVersion.js.map +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/queues/localAPI.ts"],"sourcesContent":["import type { BaseJob, RunningJobFromTask } from './config/types/workflowTypes.js'\n\nimport {\n createLocalReq,\n Forbidden,\n type Job,\n type Payload,\n type PayloadRequest,\n type Sort,\n type TypedJobs,\n type Where,\n} from '../index.js'\nimport { jobAfterRead, jobsCollectionSlug } from './config/collection.js'\nimport { handleSchedules, type HandleSchedulesResult } from './operations/handleSchedules/index.js'\nimport { runJobs } from './operations/runJobs/index.js'\nimport { updateJob, updateJobs } from './utilities/updateJob.js'\n\nexport type RunJobsSilent =\n | {\n error?: boolean\n info?: boolean\n }\n | boolean\nexport const getJobsLocalAPI = (payload: Payload) => ({\n handleSchedules: async (args?: {\n /**\n * If you want to schedule jobs from all queues, set this to true.\n * If you set this to true, the `queue` property will be ignored.\n *\n * @default false\n */\n allQueues?: boolean\n // By default, schedule all queues - only scheduling jobs scheduled to be added to the `default` queue would not make sense\n // here, as you'd usually specify a different queue than `default` here, especially if this is used in combination with autorun.\n // The `queue` property for setting up schedules is required, and not optional.\n /**\n * If you want to only schedule jobs that are set to schedule in a specific queue, set this to the queue name.\n *\n * @default jobs from the `default` queue will be executed.\n */\n queue?: string\n req?: PayloadRequest\n }): Promise<HandleSchedulesResult> => {\n const newReq: PayloadRequest = args?.req ?? (await createLocalReq({}, payload))\n\n return await handleSchedules({\n allQueues: args?.allQueues,\n queue: args?.queue,\n req: newReq,\n })\n },\n queue: async <\n // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents\n TTaskOrWorkflowSlug extends keyof TypedJobs['tasks'] | keyof TypedJobs['workflows'],\n >(\n args:\n | {\n input: TypedJobs['tasks'][TTaskOrWorkflowSlug]['input']\n meta?: BaseJob['meta']\n /**\n * If set to false, access control as defined in jobsConfig.access.queue will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.queue defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n /**\n * The queue to add the job to.\n * If not specified, the job will be added to the default queue.\n *\n * @default 'default'\n */\n queue?: string\n req?: PayloadRequest\n task: TTaskOrWorkflowSlug extends keyof TypedJobs['tasks'] ? TTaskOrWorkflowSlug : never\n waitUntil?: Date\n workflow?: never\n }\n | {\n input: TypedJobs['workflows'][TTaskOrWorkflowSlug]['input']\n meta?: BaseJob['meta']\n /**\n * If set to false, access control as defined in jobsConfig.access.queue will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.queue defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n /**\n * The queue to add the job to.\n * If not specified, the job will be added to the default queue.\n *\n * @default 'default'\n */\n queue?: string\n req?: PayloadRequest\n task?: never\n waitUntil?: Date\n workflow: TTaskOrWorkflowSlug extends keyof TypedJobs['workflows']\n ? TTaskOrWorkflowSlug\n : never\n },\n ): Promise<\n TTaskOrWorkflowSlug extends keyof TypedJobs['workflows']\n ? Job<TTaskOrWorkflowSlug>\n : RunningJobFromTask<TTaskOrWorkflowSlug>\n > => {\n const overrideAccess = args?.overrideAccess !== false\n const req: PayloadRequest = args.req ?? (await createLocalReq({}, payload))\n\n if (!overrideAccess) {\n /**\n * By default, jobsConfig.access.queue will be `defaultAccess` which is a function that returns `true` if the user is logged in.\n */\n const accessFn = payload.config.jobs?.access?.queue ?? (() => true)\n const hasAccess = await accessFn({ req })\n if (!hasAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n let queue: string | undefined = undefined\n\n // If user specifies queue, use that\n if (args.queue) {\n queue = args.queue\n } else if (args.workflow) {\n // Otherwise, if there is a workflow specified, and it has a default queue to use,\n // use that\n const workflow = payload.config.jobs?.workflows?.find(({ slug }) => slug === args.workflow)\n if (workflow?.queue) {\n queue = workflow.queue\n }\n }\n\n const data: Partial<Job> = {\n input: args.input,\n }\n\n if (queue) {\n data.queue = queue\n }\n if (args.waitUntil) {\n data.waitUntil = args.waitUntil?.toISOString()\n }\n if (args.workflow) {\n data.workflowSlug = args.workflow as string\n }\n if (args.task) {\n data.taskSlug = args.task as string\n }\n\n if (args.meta) {\n data.meta = args.meta\n }\n\n // Compute concurrency key from workflow or task config (only if feature is enabled)\n if (payload.config.jobs?.enableConcurrencyControl) {\n let concurrencyKey: null | string = null\n let supersedes = false\n const queueName = queue || 'default'\n\n if (args.workflow) {\n const workflow = payload.config.jobs?.workflows?.find(({ slug }) => slug === args.workflow)\n if (workflow?.concurrency) {\n const concurrencyConfig = workflow.concurrency\n if (typeof concurrencyConfig === 'function') {\n concurrencyKey = concurrencyConfig({ input: args.input, queue: queueName })\n } else {\n concurrencyKey = concurrencyConfig.key({ input: args.input, queue: queueName })\n supersedes = concurrencyConfig.supersedes ?? false\n }\n }\n } else if (args.task) {\n const task = payload.config.jobs?.tasks?.find(({ slug }) => slug === args.task)\n if (task?.concurrency) {\n const concurrencyConfig = task.concurrency\n if (typeof concurrencyConfig === 'function') {\n concurrencyKey = concurrencyConfig({ input: args.input, queue: queueName })\n } else {\n concurrencyKey = concurrencyConfig.key({ input: args.input, queue: queueName })\n supersedes = concurrencyConfig.supersedes ?? false\n }\n }\n }\n\n if (concurrencyKey) {\n data.concurrencyKey = concurrencyKey\n\n // If supersedes is enabled, delete older pending jobs with the same key\n if (supersedes) {\n if (payload.config.jobs.runHooks) {\n await payload.delete({\n collection: jobsCollectionSlug,\n depth: 0,\n disableTransaction: true,\n where: {\n and: [\n { concurrencyKey: { equals: concurrencyKey } },\n { processing: { equals: false } },\n { completedAt: { exists: false } },\n ],\n },\n })\n } else {\n await payload.db.deleteMany({\n collection: jobsCollectionSlug,\n req,\n where: {\n and: [\n { concurrencyKey: { equals: concurrencyKey } },\n { processing: { equals: false } },\n { completedAt: { exists: false } },\n ],\n },\n })\n }\n }\n }\n }\n\n type ReturnType = TTaskOrWorkflowSlug extends keyof TypedJobs['workflows']\n ? Job<TTaskOrWorkflowSlug>\n : RunningJobFromTask<TTaskOrWorkflowSlug> // Type assertion is still needed here\n\n if (payload?.config?.jobs?.depth || payload?.config?.jobs?.runHooks) {\n console.log('[Queue] creating new job with data (legacy)', data)\n return (await payload.create({\n collection: jobsCollectionSlug,\n data,\n depth: payload.config.jobs.depth ?? 0,\n overrideAccess,\n req,\n })) as ReturnType\n } else {\n console.log('[Queue] creating new job with data', data)\n\n return jobAfterRead({\n config: payload.config,\n doc: await payload.db.create({\n collection: jobsCollectionSlug,\n data,\n req,\n }),\n }) as unknown as ReturnType\n }\n },\n\n run: async (args?: {\n /**\n * If you want to run jobs from all queues, set this to true.\n * If you set this to true, the `queue` property will be ignored.\n *\n * @default false\n */\n allQueues?: boolean\n /**\n * The maximum number of jobs to run in this invocation\n *\n * @default 10\n */\n limit?: number\n /**\n * If set to false, access control as defined in jobsConfig.access.run will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.run defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Adjust the job processing order using a Payload sort string.\n *\n * FIFO would equal `createdAt` and LIFO would equal `-createdAt`.\n */\n processingOrder?: Sort\n /**\n * If you want to run jobs from a specific queue, set this to the queue name.\n *\n * @default jobs from the `default` queue will be executed.\n */\n queue?: string\n randomID?: string\n req?: PayloadRequest\n /**\n * By default, jobs are run in parallel.\n * If you want to run them in sequence, set this to true.\n */\n sequential?: boolean\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n where?: Where\n }): Promise<ReturnType<typeof runJobs>> => {\n console.log(`[${args?.randomID}] 1`)\n const newReq: PayloadRequest = args?.req ?? (await createLocalReq({}, payload))\n\n return await runJobs({\n allQueues: args?.allQueues,\n limit: args?.limit,\n overrideAccess: args?.overrideAccess !== false,\n processingOrder: args?.processingOrder,\n queue: args?.queue,\n randomID: args?.randomID,\n req: newReq,\n sequential: args?.sequential,\n silent: args?.silent,\n where: args?.where,\n })\n },\n\n runByID: async (args: {\n id: number | string\n /**\n * If set to false, access control as defined in jobsConfig.access.run will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.run defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n req?: PayloadRequest\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n }): Promise<ReturnType<typeof runJobs>> => {\n const newReq: PayloadRequest = args.req ?? (await createLocalReq({}, payload))\n\n return await runJobs({\n id: args.id,\n overrideAccess: args.overrideAccess !== false,\n req: newReq,\n silent: args.silent,\n })\n },\n\n cancel: async (args: {\n /**\n * If set to false, access control as defined in jobsConfig.access.cancel will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.cancel defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n queue?: string\n req?: PayloadRequest\n where: Where\n }): Promise<void> => {\n const req: PayloadRequest = args.req ?? (await createLocalReq({}, payload))\n\n const overrideAccess = args.overrideAccess !== false\n if (!overrideAccess) {\n /**\n * By default, jobsConfig.access.cancel will be `defaultAccess` which is a function that returns `true` if the user is logged in.\n */\n const accessFn = payload.config.jobs?.access?.cancel ?? (() => true)\n const hasAccess = await accessFn({ req })\n if (!hasAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n const and: Where[] = [\n args.where,\n {\n completedAt: {\n exists: false,\n },\n },\n {\n hasError: {\n not_equals: true,\n },\n },\n ]\n\n if (args.queue) {\n and.push({\n queue: {\n equals: args.queue,\n },\n })\n }\n\n await updateJobs({\n data: {\n completedAt: null,\n error: {\n cancelled: true,\n },\n hasError: true,\n processing: false,\n waitUntil: null,\n },\n depth: 0, // No depth, since we're not returning\n disableTransaction: true,\n req,\n returning: false,\n where: { and },\n })\n },\n\n cancelByID: async (args: {\n id: number | string\n /**\n * If set to false, access control as defined in jobsConfig.access.cancel will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.cancel defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n req?: PayloadRequest\n }): Promise<void> => {\n const req: PayloadRequest = args.req ?? (await createLocalReq({}, payload))\n\n const overrideAccess = args.overrideAccess !== false\n if (!overrideAccess) {\n /**\n * By default, jobsConfig.access.cancel will be `defaultAccess` which is a function that returns `true` if the user is logged in.\n */\n const accessFn = payload.config.jobs?.access?.cancel ?? (() => true)\n const hasAccess = await accessFn({ req })\n if (!hasAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n await updateJob({\n id: args.id,\n data: {\n completedAt: null,\n error: {\n cancelled: true,\n },\n hasError: true,\n processing: false,\n waitUntil: null,\n },\n depth: 0, // No depth, since we're not returning\n disableTransaction: true,\n req,\n returning: false,\n })\n },\n})\n"],"names":["createLocalReq","Forbidden","jobAfterRead","jobsCollectionSlug","handleSchedules","runJobs","updateJob","updateJobs","getJobsLocalAPI","payload","args","newReq","req","allQueues","queue","overrideAccess","accessFn","config","jobs","access","hasAccess","t","undefined","workflow","workflows","find","slug","data","input","waitUntil","toISOString","workflowSlug","task","taskSlug","meta","enableConcurrencyControl","concurrencyKey","supersedes","queueName","concurrency","concurrencyConfig","key","tasks","runHooks","delete","collection","depth","disableTransaction","where","and","equals","processing","completedAt","exists","db","deleteMany","console","log","create","doc","run","randomID","limit","processingOrder","sequential","silent","runByID","id","cancel","hasError","not_equals","push","error","cancelled","returning","cancelByID"],"mappings":"AAEA,SACEA,cAAc,EACdC,SAAS,QAOJ,cAAa;AACpB,SAASC,YAAY,EAAEC,kBAAkB,QAAQ,yBAAwB;AACzE,SAASC,eAAe,QAAoC,wCAAuC;AACnG,SAASC,OAAO,QAAQ,gCAA+B;AACvD,SAASC,SAAS,EAAEC,UAAU,QAAQ,2BAA0B;AAQhE,OAAO,MAAMC,kBAAkB,CAACC,UAAsB,CAAA;QACpDL,iBAAiB,OAAOM;YAmBtB,MAAMC,SAAyBD,MAAME,OAAQ,MAAMZ,eAAe,CAAC,GAAGS;YAEtE,OAAO,MAAML,gBAAgB;gBAC3BS,WAAWH,MAAMG;gBACjBC,OAAOJ,MAAMI;gBACbF,KAAKD;YACP;QACF;QACAG,OAAO,O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LoC,QAAQxC,KAAKI,KAAK;oBACpB;gBACF;YACF;YAEA,MAAMP,WAAW;gBACfoB,MAAM;oBACJyB,aAAa;oBACboB,OAAO;wBACLC,WAAW;oBACb;oBACAJ,UAAU;oBACVlB,YAAY;oBACZtB,WAAW;gBACb;gBACAiB,OAAO;gBACPC,oBAAoB;gBACpBnC;gBACA8D,WAAW;gBACX1B,OAAO;oBAAEC;gBAAI;YACf;QACF;QAEA0B,YAAY,OAAOjE;YAajB,MAAME,MAAsBF,KAAKE,GAAG,IAAK,MAAMZ,eAAe,CAAC,GAAGS;YAElE,MAAMM,iBAAiBL,KAAKK,cAAc,KAAK;YAC/C,IAAI,CAACA,gBAAgB;gBACnB;;OAEC,GACD,MAAMC,WAAWP,QAAQQ,MAAM,CAACC,IAAI,EAAEC,QAAQiD,UAAW,CAAA,IAAM,IAAG;gBAClE,MAAMhD,YAAY,MAAMJ,SAAS;oBAAEJ;gBAAI;gBACvC,IAAI,CAACQ,WAAW;oBACd,MAAM,IAAInB,UAAUW,IAAIS,CAAC;gBAC3B;YACF;YAEA,MAAMf,UAAU;gBACd6D,IAAIzD,KAAKyD,EAAE;gBACXxC,MAAM;oBACJyB,aAAa;oBACboB,OAAO;wBACLC,WAAW;oBACb;oBACAJ,UAAU;oBACVlB,YAAY;oBACZtB,WAAW;gBACb;gBACAiB,OAAO;gBACPC,oBAAoB;gBACpBnC;gBACA8D,WAAW;YACb;QACF;IACF,CAAA,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/queues/localAPI.ts"],"sourcesContent":["import type { BaseJob, RunningJobFromTask } from './config/types/workflowTypes.js'\n\nimport {\n createLocalReq,\n Forbidden,\n type Job,\n type Payload,\n type PayloadRequest,\n type Sort,\n type TypedJobs,\n type Where,\n} from '../index.js'\nimport { jobAfterRead, jobsCollectionSlug } from './config/collection.js'\nimport { handleSchedules, type HandleSchedulesResult } from './operations/handleSchedules/index.js'\nimport { runJobs } from './operations/runJobs/index.js'\nimport { updateJob, updateJobs } from './utilities/updateJob.js'\n\nexport type RunJobsSilent =\n | {\n error?: boolean\n info?: boolean\n }\n | boolean\nexport const getJobsLocalAPI = (payload: Payload) => ({\n handleSchedules: async (args?: {\n /**\n * If you want to schedule jobs from all queues, set this to true.\n * If you set this to true, the `queue` property will be ignored.\n *\n * @default false\n */\n allQueues?: boolean\n // By default, schedule all queues - only scheduling jobs scheduled to be added to the `default` queue would not make sense\n // here, as you'd usually specify a different queue than `default` here, especially if this is used in combination with autorun.\n // The `queue` property for setting up schedules is required, and not optional.\n /**\n * If you want to only schedule jobs that are set to schedule in a specific queue, set this to the queue name.\n *\n * @default jobs from the `default` queue will be executed.\n */\n queue?: string\n req?: PayloadRequest\n }): Promise<HandleSchedulesResult> => {\n const newReq: PayloadRequest = args?.req ?? (await createLocalReq({}, payload))\n\n return await handleSchedules({\n allQueues: args?.allQueues,\n queue: args?.queue,\n req: newReq,\n })\n },\n queue: async <\n // eslint-disable-next-line @typescript-eslint/no-duplicate-type-constituents\n TTaskOrWorkflowSlug extends keyof TypedJobs['tasks'] | keyof TypedJobs['workflows'],\n >(\n args:\n | {\n input: TypedJobs['tasks'][TTaskOrWorkflowSlug]['input']\n meta?: BaseJob['meta']\n /**\n * If set to false, access control as defined in jobsConfig.access.queue will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.queue defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n /**\n * The queue to add the job to.\n * If not specified, the job will be added to the default queue.\n *\n * @default 'default'\n */\n queue?: string\n req?: PayloadRequest\n task: TTaskOrWorkflowSlug extends keyof TypedJobs['tasks'] ? TTaskOrWorkflowSlug : never\n waitUntil?: Date\n workflow?: never\n }\n | {\n input: TypedJobs['workflows'][TTaskOrWorkflowSlug]['input']\n meta?: BaseJob['meta']\n /**\n * If set to false, access control as defined in jobsConfig.access.queue will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.queue defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n /**\n * The queue to add the job to.\n * If not specified, the job will be added to the default queue.\n *\n * @default 'default'\n */\n queue?: string\n req?: PayloadRequest\n task?: never\n waitUntil?: Date\n workflow: TTaskOrWorkflowSlug extends keyof TypedJobs['workflows']\n ? TTaskOrWorkflowSlug\n : never\n },\n ): Promise<\n TTaskOrWorkflowSlug extends keyof TypedJobs['workflows']\n ? Job<TTaskOrWorkflowSlug>\n : RunningJobFromTask<TTaskOrWorkflowSlug>\n > => {\n const overrideAccess = args?.overrideAccess !== false\n const req: PayloadRequest = args.req ?? (await createLocalReq({}, payload))\n\n if (!overrideAccess) {\n /**\n * By default, jobsConfig.access.queue will be `defaultAccess` which is a function that returns `true` if the user is logged in.\n */\n const accessFn = payload.config.jobs?.access?.queue ?? (() => true)\n const hasAccess = await accessFn({ req })\n if (!hasAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n let queue: string | undefined = undefined\n\n // If user specifies queue, use that\n if (args.queue) {\n queue = args.queue\n } else if (args.workflow) {\n // Otherwise, if there is a workflow specified, and it has a default queue to use,\n // use that\n const workflow = payload.config.jobs?.workflows?.find(({ slug }) => slug === args.workflow)\n if (workflow?.queue) {\n queue = workflow.queue\n }\n }\n\n const data: Partial<Job> = {\n input: args.input,\n }\n\n if (queue) {\n data.queue = queue\n }\n if (args.waitUntil) {\n data.waitUntil = args.waitUntil?.toISOString()\n }\n if (args.workflow) {\n data.workflowSlug = args.workflow as string\n }\n if (args.task) {\n data.taskSlug = args.task as string\n }\n\n if (args.meta) {\n data.meta = args.meta\n }\n\n // Compute concurrency key from workflow or task config (only if feature is enabled)\n if (payload.config.jobs?.enableConcurrencyControl) {\n let concurrencyKey: null | string = null\n let supersedes = false\n const queueName = queue || 'default'\n\n if (args.workflow) {\n const workflow = payload.config.jobs?.workflows?.find(({ slug }) => slug === args.workflow)\n if (workflow?.concurrency) {\n const concurrencyConfig = workflow.concurrency\n if (typeof concurrencyConfig === 'function') {\n concurrencyKey = concurrencyConfig({ input: args.input, queue: queueName })\n } else {\n concurrencyKey = concurrencyConfig.key({ input: args.input, queue: queueName })\n supersedes = concurrencyConfig.supersedes ?? false\n }\n }\n } else if (args.task) {\n const task = payload.config.jobs?.tasks?.find(({ slug }) => slug === args.task)\n if (task?.concurrency) {\n const concurrencyConfig = task.concurrency\n if (typeof concurrencyConfig === 'function') {\n concurrencyKey = concurrencyConfig({ input: args.input, queue: queueName })\n } else {\n concurrencyKey = concurrencyConfig.key({ input: args.input, queue: queueName })\n supersedes = concurrencyConfig.supersedes ?? false\n }\n }\n }\n\n if (concurrencyKey) {\n data.concurrencyKey = concurrencyKey\n\n // If supersedes is enabled, delete older pending jobs with the same key\n if (supersedes) {\n if (payload.config.jobs.runHooks) {\n await payload.delete({\n collection: jobsCollectionSlug,\n depth: 0,\n disableTransaction: true,\n where: {\n and: [\n { concurrencyKey: { equals: concurrencyKey } },\n { processing: { equals: false } },\n { completedAt: { exists: false } },\n ],\n },\n })\n } else {\n await payload.db.deleteMany({\n collection: jobsCollectionSlug,\n req,\n where: {\n and: [\n { concurrencyKey: { equals: concurrencyKey } },\n { processing: { equals: false } },\n { completedAt: { exists: false } },\n ],\n },\n })\n }\n }\n }\n }\n\n type ReturnType = TTaskOrWorkflowSlug extends keyof TypedJobs['workflows']\n ? Job<TTaskOrWorkflowSlug>\n : RunningJobFromTask<TTaskOrWorkflowSlug> // Type assertion is still needed here\n\n if (payload?.config?.jobs?.depth || payload?.config?.jobs?.runHooks) {\n return (await payload.create({\n collection: jobsCollectionSlug,\n data,\n depth: payload.config.jobs.depth ?? 0,\n overrideAccess,\n req,\n })) as ReturnType\n } else {\n return jobAfterRead({\n config: payload.config,\n doc: await payload.db.create({\n collection: jobsCollectionSlug,\n data,\n req,\n }),\n }) as unknown as ReturnType\n }\n },\n\n run: async (args?: {\n /**\n * If you want to run jobs from all queues, set this to true.\n * If you set this to true, the `queue` property will be ignored.\n *\n * @default false\n */\n allQueues?: boolean\n /**\n * The maximum number of jobs to run in this invocation\n *\n * @default 10\n */\n limit?: number\n /**\n * If set to false, access control as defined in jobsConfig.access.run will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.run defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n /**\n * Adjust the job processing order using a Payload sort string.\n *\n * FIFO would equal `createdAt` and LIFO would equal `-createdAt`.\n */\n processingOrder?: Sort\n /**\n * If you want to run jobs from a specific queue, set this to the queue name.\n *\n * @default jobs from the `default` queue will be executed.\n */\n queue?: string\n req?: PayloadRequest\n /**\n * By default, jobs are run in parallel.\n * If you want to run them in sequence, set this to true.\n */\n sequential?: boolean\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n where?: Where\n }): Promise<ReturnType<typeof runJobs>> => {\n const newReq: PayloadRequest = args?.req ?? (await createLocalReq({}, payload))\n\n return await runJobs({\n allQueues: args?.allQueues,\n limit: args?.limit,\n overrideAccess: args?.overrideAccess !== false,\n processingOrder: args?.processingOrder,\n queue: args?.queue,\n req: newReq,\n sequential: args?.sequential,\n silent: args?.silent,\n where: args?.where,\n })\n },\n\n runByID: async (args: {\n id: number | string\n /**\n * If set to false, access control as defined in jobsConfig.access.run will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.run defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n req?: PayloadRequest\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n }): Promise<ReturnType<typeof runJobs>> => {\n const newReq: PayloadRequest = args.req ?? (await createLocalReq({}, payload))\n\n return await runJobs({\n id: args.id,\n overrideAccess: args.overrideAccess !== false,\n req: newReq,\n silent: args.silent,\n })\n },\n\n cancel: async (args: {\n /**\n * If set to false, access control as defined in jobsConfig.access.cancel will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.cancel defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n queue?: string\n req?: PayloadRequest\n where: Where\n }): Promise<void> => {\n const req: PayloadRequest = args.req ?? (await createLocalReq({}, payload))\n\n const overrideAccess = args.overrideAccess !== false\n if (!overrideAccess) {\n /**\n * By default, jobsConfig.access.cancel will be `defaultAccess` which is a function that returns `true` if the user is logged in.\n */\n const accessFn = payload.config.jobs?.access?.cancel ?? (() => true)\n const hasAccess = await accessFn({ req })\n if (!hasAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n const and: Where[] = [\n args.where,\n {\n completedAt: {\n exists: false,\n },\n },\n {\n hasError: {\n not_equals: true,\n },\n },\n ]\n\n if (args.queue) {\n and.push({\n queue: {\n equals: args.queue,\n },\n })\n }\n\n await updateJobs({\n data: {\n completedAt: null,\n error: {\n cancelled: true,\n },\n hasError: true,\n processing: false,\n waitUntil: null,\n },\n depth: 0, // No depth, since we're not returning\n disableTransaction: true,\n req,\n returning: false,\n where: { and },\n })\n },\n\n cancelByID: async (args: {\n id: number | string\n /**\n * If set to false, access control as defined in jobsConfig.access.cancel will be run.\n * By default, this is true and no access control will be run.\n * If you set this to false and do not have jobsConfig.access.cancel defined, the default access control will be\n * run (which is a function that returns `true` if the user is logged in).\n *\n * @default true\n */\n overrideAccess?: boolean\n req?: PayloadRequest\n }): Promise<void> => {\n const req: PayloadRequest = args.req ?? (await createLocalReq({}, payload))\n\n const overrideAccess = args.overrideAccess !== false\n if (!overrideAccess) {\n /**\n * By default, jobsConfig.access.cancel will be `defaultAccess` which is a function that returns `true` if the user is logged in.\n */\n const accessFn = payload.config.jobs?.access?.cancel ?? (() => true)\n const hasAccess = await accessFn({ req })\n if (!hasAccess) {\n throw new Forbidden(req.t)\n }\n }\n\n await updateJob({\n id: args.id,\n data: {\n completedAt: null,\n error: {\n cancelled: true,\n },\n hasError: true,\n processing: false,\n waitUntil: null,\n },\n depth: 0, // No depth, since we're not returning\n disableTransaction: true,\n req,\n returning: false,\n })\n },\n})\n"],"names":["createLocalReq","Forbidden","jobAfterRead","jobsCollectionSlug","handleSchedules","runJobs","updateJob","updateJobs","getJobsLocalAPI","payload","args","newReq","req","allQueues","queue","overrideAccess","accessFn","config","jobs","access","hasAccess","t","undefined","workflow","workflows","find","slug","data","input","waitUntil","toISOString","workflowSlug","task","taskSlug","meta","enableConcurrencyControl","concurrencyKey","supersedes","queueName","concurrency","concurrencyConfig","key","tasks","runHooks","delete","collection","depth","disableTransaction","where","and","equals","processing","completedAt","exists","db","deleteMany","create","doc","run","limit","processingOrder","sequential","silent","runByID","id","cancel","hasError","not_equals","push","error","cancelled","returning","cancelByID"],"mappings":"AAEA,SACEA,cAAc,EACdC,SAAS,QAOJ,cAAa;AACpB,SAASC,YAAY,EAAEC,kBAAkB,QAAQ,yBAAwB;AACzE,SAASC,eAAe,QAAoC,wCAAuC;AACnG,SAASC,OAAO,QAAQ,gCAA+B;AACvD,SAASC,SAAS,EAAEC,UAAU,QAAQ,2BAA0B;AAQhE,OAAO,MAAMC,kBAAkB,CAACC,UAAsB,CAAA;QACpDL,iBAAiB,OAAOM;YAmBtB,MAAMC,SAAyBD,MAAME,OAAQ,MAAMZ,eAAe,CAAC,GAAGS;YAEtE,OAAO,MAAML,gBAAgB;gBAC3BS,WAAWH,MAAMG;gBACjBC,OAAOJ,MAAMI;gBACbF,KAAKD;YACP;QACF;QACAG,OAAO,OAILJ;YAwDA,MAAMK,iBAAiBL,MAAMK,mBAAmB;YAChD,MAAMH,MAAsBF,KAAKE,GAAG,IAAK,MAAMZ,eAAe,CAAC,GAAGS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MAAsBF,KAAKE,GAAG,IAAK,MAAMZ,eAAe,CAAC,GAAGS;YAElE,MAAMM,iBAAiBL,KAAKK,cAAc,KAAK;YAC/C,IAAI,CAACA,gBAAgB;gBACnB;;OAEC,GACD,MAAMC,WAAWP,QAAQQ,MAAM,CAACC,IAAI,EAAEC,QAAQ8C,UAAW,CAAA,IAAM,IAAG;gBAClE,MAAM7C,YAAY,MAAMJ,SAAS;oBAAEJ;gBAAI;gBACvC,IAAI,CAACQ,WAAW;oBACd,MAAM,IAAInB,UAAUW,IAAIS,CAAC;gBAC3B;YACF;YAEA,MAAMf,UAAU;gBACd0D,IAAItD,KAAKsD,EAAE;gBACXrC,MAAM;oBACJyB,aAAa;oBACbiB,OAAO;wBACLC,WAAW;oBACb;oBACAJ,UAAU;oBACVf,YAAY;oBACZtB,WAAW;gBACb;gBACAiB,OAAO;gBACPC,oBAAoB;gBACpBnC;gBACA2D,WAAW;YACb;QACF;IACF,CAAA,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/queues/operations/runJobs/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAG1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAarD,MAAM,MAAM,WAAW,GAAG;IACxB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,IAAI,CAAA;IACtB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/queues/operations/runJobs/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAG1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAarD,MAAM,MAAM,WAAW,GAAG;IACxB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,IAAI,CAAA;IACtB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,aAAa,CAAA;IACtB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd,CAAA;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IACxC;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;OAEG;IACH,wBAAwB,EAAE,MAAM,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,OAAO,SAAgB,WAAW,KAAG,OAAO,CAAC,aAAa,CAyctE,CAAA"}
|
|
@@ -9,14 +9,7 @@ import { importHandlerPath } from './runJob/importHandlerPath.js';
|
|
|
9
9
|
import { runJob } from './runJob/index.js';
|
|
10
10
|
import { runJSONJob } from './runJSONJob/index.js';
|
|
11
11
|
export const runJobs = async (args)=>{
|
|
12
|
-
const { id, allQueues = false, limit = 10, overrideAccess, processingOrder, queue = 'default',
|
|
13
|
-
console.log(`[${randomID}] 2 - runJobs started`, {
|
|
14
|
-
id,
|
|
15
|
-
allQueues,
|
|
16
|
-
limit,
|
|
17
|
-
queue,
|
|
18
|
-
sequential
|
|
19
|
-
});
|
|
12
|
+
const { id, allQueues = false, limit = 10, overrideAccess, processingOrder, queue = 'default', req, req: { payload, payload: { config: { jobs: jobsConfig } } }, sequential, silent = false, where: whereFromProps } = args;
|
|
20
13
|
if (!overrideAccess) {
|
|
21
14
|
/**
|
|
22
15
|
* By default, jobsConfig.access.run will be `defaultAccess` which is a function that returns `true` if the user is logged in.
|
|
@@ -28,7 +21,6 @@ export const runJobs = async (args)=>{
|
|
|
28
21
|
throw new Forbidden(req.t);
|
|
29
22
|
}
|
|
30
23
|
}
|
|
31
|
-
console.log(`[${randomID}] 3 - access check passed`);
|
|
32
24
|
const and = [
|
|
33
25
|
{
|
|
34
26
|
completedAt: {
|
|
@@ -70,7 +62,6 @@ export const runJobs = async (args)=>{
|
|
|
70
62
|
if (whereFromProps) {
|
|
71
63
|
and.push(whereFromProps);
|
|
72
64
|
}
|
|
73
|
-
console.log(`[${args?.randomID}] 4`);
|
|
74
65
|
// Only enforce concurrency controls if the feature is enabled
|
|
75
66
|
if (jobsConfig.enableConcurrencyControl) {
|
|
76
67
|
// Find currently running jobs with concurrency keys to enforce exclusive concurrency
|
|
@@ -131,15 +122,10 @@ export const runJobs = async (args)=>{
|
|
|
131
122
|
});
|
|
132
123
|
}
|
|
133
124
|
}
|
|
134
|
-
console.log(`[${randomID}] 5 - concurrency control done, querying jobs`, {
|
|
135
|
-
id,
|
|
136
|
-
enableConcurrencyControl: jobsConfig.enableConcurrencyControl
|
|
137
|
-
});
|
|
138
125
|
// Find all jobs and ensure we set job to processing: true as early as possible to reduce the chance of
|
|
139
126
|
// the same job being picked up by another worker
|
|
140
127
|
let jobs = [];
|
|
141
128
|
if (id) {
|
|
142
|
-
console.log(`[${randomID}] 5.1 - fetching single job by ID: ${id}`);
|
|
143
129
|
// Only one job to run
|
|
144
130
|
const job = await updateJob({
|
|
145
131
|
id,
|
|
@@ -151,16 +137,12 @@ export const runJobs = async (args)=>{
|
|
|
151
137
|
req,
|
|
152
138
|
returning: true
|
|
153
139
|
});
|
|
154
|
-
console.log(`[${randomID}] 5.2 - single job fetched`, {
|
|
155
|
-
found: !!job
|
|
156
|
-
});
|
|
157
140
|
if (job) {
|
|
158
141
|
jobs = [
|
|
159
142
|
job
|
|
160
143
|
];
|
|
161
144
|
}
|
|
162
145
|
} else {
|
|
163
|
-
console.log(`[${randomID}] 5.3 - fetching multiple jobs with limit: ${limit}`);
|
|
164
146
|
let defaultProcessingOrder = payload.collections[jobsCollectionSlug]?.config.defaultSort ?? 'createdAt';
|
|
165
147
|
const processingOrderConfig = jobsConfig.processingOrder;
|
|
166
148
|
if (typeof processingOrderConfig === 'function') {
|
|
@@ -174,12 +156,10 @@ export const runJobs = async (args)=>{
|
|
|
174
156
|
} else if (typeof processingOrderConfig === 'string') {
|
|
175
157
|
defaultProcessingOrder = processingOrderConfig;
|
|
176
158
|
}
|
|
177
|
-
console.log(`[${randomID}] 5.3.1 - using where query "and":`, and);
|
|
178
159
|
const updatedDocs = await updateJobs({
|
|
179
160
|
data: {
|
|
180
161
|
processing: true
|
|
181
162
|
},
|
|
182
|
-
debugID: randomID,
|
|
183
163
|
depth: jobsConfig.depth,
|
|
184
164
|
disableTransaction: true,
|
|
185
165
|
limit,
|
|
@@ -190,38 +170,11 @@ export const runJobs = async (args)=>{
|
|
|
190
170
|
and
|
|
191
171
|
}
|
|
192
172
|
});
|
|
193
|
-
console.log(`[${randomID}] 5.4 - multiple jobs fetched`, {
|
|
194
|
-
count: updatedDocs?.length ?? 0
|
|
195
|
-
});
|
|
196
|
-
if ((updatedDocs?.length ?? 0) > 0) {
|
|
197
|
-
console.log(`[${randomID}] 5.5 - jobs found! fetched:`, {
|
|
198
|
-
jobs: updatedDocs
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
// Fetch ALL jobs using payload.db.find({})
|
|
202
|
-
const allJobs = await payload.db.find({
|
|
203
|
-
collection: jobsCollectionSlug,
|
|
204
|
-
limit: 0,
|
|
205
|
-
req
|
|
206
|
-
});
|
|
207
|
-
console.log(`[${randomID}] 5.6 - all jobs fetched`, {
|
|
208
|
-
allJobs: allJobs?.docs,
|
|
209
|
-
count: allJobs?.totalDocs
|
|
210
|
-
});
|
|
211
|
-
const anyRunnableJobs = allJobs?.docs?.some((job)=>job?.processing === false && job?.hasError === false && !job?.completedAt && !job?.waitUntil);
|
|
212
|
-
if (anyRunnableJobs && updatedDocs?.length === 0) {
|
|
213
|
-
console.log(`[${randomID}] 5.6.1 - potential issue here.`);
|
|
214
|
-
}
|
|
215
173
|
if (updatedDocs) {
|
|
216
174
|
jobs = updatedDocs;
|
|
217
175
|
}
|
|
218
176
|
}
|
|
219
|
-
console.log(`[${randomID}] 6 - jobs to process`, {
|
|
220
|
-
count: jobs.length,
|
|
221
|
-
jobIds: jobs.map((j)=>j.id)
|
|
222
|
-
});
|
|
223
177
|
if (!jobs.length) {
|
|
224
|
-
console.log(`[${randomID}] 7 - no jobs found, returning early`);
|
|
225
178
|
return {
|
|
226
179
|
noJobsRemaining: true,
|
|
227
180
|
remainingJobsFromQueried: 0
|
|
@@ -254,7 +207,6 @@ export const runJobs = async (args)=>{
|
|
|
254
207
|
data: {
|
|
255
208
|
processing: false
|
|
256
209
|
},
|
|
257
|
-
debugID: randomID,
|
|
258
210
|
disableTransaction: true,
|
|
259
211
|
req,
|
|
260
212
|
returning: false,
|
|
@@ -268,17 +220,12 @@ export const runJobs = async (args)=>{
|
|
|
268
220
|
// Use only the filtered jobs going forward
|
|
269
221
|
jobs = jobsToRun;
|
|
270
222
|
}
|
|
271
|
-
console.log(`[${randomID}] 8 - concurrency dedup done`, {
|
|
272
|
-
jobsToRun: jobs.length
|
|
273
|
-
});
|
|
274
223
|
if (!jobs.length) {
|
|
275
|
-
console.log(`[${randomID}] 9 - all jobs were duplicates, returning early`);
|
|
276
224
|
return {
|
|
277
225
|
noJobsRemaining: false,
|
|
278
226
|
remainingJobsFromQueried: 0
|
|
279
227
|
};
|
|
280
228
|
}
|
|
281
|
-
console.log(`[${randomID}] 10 - preparing to run ${jobs.length} jobs`);
|
|
282
229
|
/**
|
|
283
230
|
* Just for logging purposes, we want to know how many jobs are new and how many are existing (= already been tried).
|
|
284
231
|
* This is only for logs - in the end we still want to run all jobs, regardless of whether they are new or existing.
|
|
@@ -293,10 +240,6 @@ export const runJobs = async (args)=>{
|
|
|
293
240
|
existingJobs: [],
|
|
294
241
|
newJobs: []
|
|
295
242
|
});
|
|
296
|
-
console.log(`[${randomID}] 11 - job breakdown`, {
|
|
297
|
-
existingJobCount: existingJobs.length,
|
|
298
|
-
newJobCount: newJobs.length
|
|
299
|
-
});
|
|
300
243
|
if (!silent || typeof silent === 'object' && !silent.info) {
|
|
301
244
|
payload.logger.info({
|
|
302
245
|
msg: `Running ${jobs.length} jobs.`,
|
|
@@ -306,11 +249,6 @@ export const runJobs = async (args)=>{
|
|
|
306
249
|
}
|
|
307
250
|
const successfullyCompletedJobs = [];
|
|
308
251
|
const runSingleJob = async (job)=>{
|
|
309
|
-
console.log(`[${randomID}] job:${job.id} - starting`, {
|
|
310
|
-
taskSlug: job.taskSlug,
|
|
311
|
-
totalTried: job.totalTried,
|
|
312
|
-
workflowSlug: job.workflowSlug
|
|
313
|
-
});
|
|
314
252
|
if (!job.workflowSlug && !job.taskSlug) {
|
|
315
253
|
throw new Error('Job must have either a workflowSlug or a taskSlug');
|
|
316
254
|
}
|
|
@@ -324,7 +262,6 @@ export const runJobs = async (args)=>{
|
|
|
324
262
|
}
|
|
325
263
|
};
|
|
326
264
|
if (!workflowConfig) {
|
|
327
|
-
console.log(`[${randomID}] job:${job.id} - no workflow config found, skipping`);
|
|
328
265
|
return {
|
|
329
266
|
id: job.id,
|
|
330
267
|
result: {
|
|
@@ -365,7 +302,6 @@ export const runJobs = async (args)=>{
|
|
|
365
302
|
}
|
|
366
303
|
}
|
|
367
304
|
if (typeof workflowHandler === 'function') {
|
|
368
|
-
console.log(`[${randomID}] job:${job.id} - running function handler`);
|
|
369
305
|
const result = await runJob({
|
|
370
306
|
job,
|
|
371
307
|
req: jobReq,
|
|
@@ -374,9 +310,6 @@ export const runJobs = async (args)=>{
|
|
|
374
310
|
workflowConfig,
|
|
375
311
|
workflowHandler
|
|
376
312
|
});
|
|
377
|
-
console.log(`[${randomID}] job:${job.id} - completed`, {
|
|
378
|
-
status: result.status
|
|
379
|
-
});
|
|
380
313
|
if (result.status === 'success') {
|
|
381
314
|
successfullyCompletedJobs.push(job.id);
|
|
382
315
|
}
|
|
@@ -385,7 +318,6 @@ export const runJobs = async (args)=>{
|
|
|
385
318
|
result
|
|
386
319
|
};
|
|
387
320
|
} else {
|
|
388
|
-
console.log(`[${randomID}] job:${job.id} - running JSON handler`);
|
|
389
321
|
const result = await runJSONJob({
|
|
390
322
|
job,
|
|
391
323
|
req: jobReq,
|
|
@@ -394,9 +326,6 @@ export const runJobs = async (args)=>{
|
|
|
394
326
|
workflowConfig,
|
|
395
327
|
workflowHandler
|
|
396
328
|
});
|
|
397
|
-
console.log(`[${randomID}] job:${job.id} - completed`, {
|
|
398
|
-
status: result.status
|
|
399
|
-
});
|
|
400
329
|
if (result.status === 'success') {
|
|
401
330
|
successfullyCompletedJobs.push(job.id);
|
|
402
331
|
}
|
|
@@ -407,9 +336,6 @@ export const runJobs = async (args)=>{
|
|
|
407
336
|
}
|
|
408
337
|
} catch (error) {
|
|
409
338
|
if (error instanceof JobCancelledError) {
|
|
410
|
-
console.log(`[${randomID}] job:${job.id} - cancelled`, {
|
|
411
|
-
message: error.message
|
|
412
|
-
});
|
|
413
339
|
if (!job.error?.cancelled || !job.hasError || job.processing || job.completedAt || job.waitUntil) {
|
|
414
340
|
// When using the local API to cancel jobs, the local API will update the job data for us to ensure the job is cancelled.
|
|
415
341
|
// But when throwing a JobCancelledError within a task or workflow handler, we are responsible for updating the job data ourselves.
|
|
@@ -438,19 +364,11 @@ export const runJobs = async (args)=>{
|
|
|
438
364
|
}
|
|
439
365
|
};
|
|
440
366
|
}
|
|
441
|
-
console.log(`[${randomID}] job:${job.id} - error thrown`, {
|
|
442
|
-
error: error instanceof Error ? error.message : String(error)
|
|
443
|
-
});
|
|
444
367
|
throw error;
|
|
445
368
|
}
|
|
446
369
|
};
|
|
447
|
-
console.log(`[${randomID}] 12 - starting job execution`, {
|
|
448
|
-
jobCount: jobs.length,
|
|
449
|
-
sequential
|
|
450
|
-
});
|
|
451
370
|
let resultsArray = [];
|
|
452
371
|
if (sequential) {
|
|
453
|
-
console.log(`[${randomID}] 12.1 - running jobs sequentially`);
|
|
454
372
|
for (const job of jobs){
|
|
455
373
|
const result = await runSingleJob(job);
|
|
456
374
|
if (result) {
|
|
@@ -458,18 +376,10 @@ export const runJobs = async (args)=>{
|
|
|
458
376
|
}
|
|
459
377
|
}
|
|
460
378
|
} else {
|
|
461
|
-
console.log(`[${randomID}] 12.2 - running jobs in parallel`);
|
|
462
379
|
const jobPromises = jobs.map(runSingleJob);
|
|
463
380
|
resultsArray = await Promise.all(jobPromises);
|
|
464
381
|
}
|
|
465
|
-
console.log(`[${randomID}] 13 - all jobs executed`, {
|
|
466
|
-
resultsCount: resultsArray.length,
|
|
467
|
-
successfulCount: successfullyCompletedJobs.length
|
|
468
|
-
});
|
|
469
382
|
if (jobsConfig.deleteJobOnComplete && successfullyCompletedJobs.length) {
|
|
470
|
-
console.log(`[${randomID}] 14 - deleting completed jobs`, {
|
|
471
|
-
count: successfullyCompletedJobs.length
|
|
472
|
-
});
|
|
473
383
|
try {
|
|
474
384
|
if (jobsConfig.runHooks) {
|
|
475
385
|
await payload.delete({
|
|
@@ -515,11 +425,6 @@ export const runJobs = async (args)=>{
|
|
|
515
425
|
remainingJobsFromQueried++; // Can be retried
|
|
516
426
|
}
|
|
517
427
|
}
|
|
518
|
-
console.log(`[${randomID}] 15 - runJobs complete`, {
|
|
519
|
-
remainingJobsFromQueried,
|
|
520
|
-
successCount: successfullyCompletedJobs.length,
|
|
521
|
-
totalProcessed: Object.keys(resultsObject).length
|
|
522
|
-
});
|
|
523
428
|
return {
|
|
524
429
|
jobStatus: resultsObject,
|
|
525
430
|
remainingJobsFromQueried
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/queues/operations/runJobs/index.ts"],"sourcesContent":["import type { Job } from '../../../index.js'\nimport type { PayloadRequest, Sort, Where } from '../../../types/index.js'\nimport type { WorkflowJSON } from '../../config/types/workflowJSONTypes.js'\nimport type { WorkflowConfig, WorkflowHandler } from '../../config/types/workflowTypes.js'\nimport type { RunJobsSilent } from '../../localAPI.js'\nimport type { RunJobResult } from './runJob/index.js'\n\nimport { Forbidden } from '../../../errors/Forbidden.js'\nimport { isolateObjectProperty } from '../../../utilities/isolateObjectProperty.js'\nimport { jobsCollectionSlug } from '../../config/collection.js'\nimport { JobCancelledError } from '../../errors/index.js'\nimport { getCurrentDate } from '../../utilities/getCurrentDate.js'\nimport { updateJob, updateJobs } from '../../utilities/updateJob.js'\nimport { getUpdateJobFunction } from './runJob/getUpdateJobFunction.js'\nimport { importHandlerPath } from './runJob/importHandlerPath.js'\nimport { runJob } from './runJob/index.js'\nimport { runJSONJob } from './runJSONJob/index.js'\n\nexport type RunJobsArgs = {\n /**\n * If you want to run jobs from all queues, set this to true.\n * If you set this to true, the `queue` property will be ignored.\n *\n * @default false\n */\n allQueues?: boolean\n /**\n * ID of the job to run\n */\n id?: number | string\n /**\n * The maximum number of jobs to run in this invocation\n *\n * @default 10\n */\n limit?: number\n overrideAccess?: boolean\n /**\n * Adjust the job processing order\n *\n * FIFO would equal `createdAt` and LIFO would equal `-createdAt`.\n *\n * @default all jobs for all queues will be executed in FIFO order.\n */\n processingOrder?: Sort\n /**\n * If you want to run jobs from a specific queue, set this to the queue name.\n *\n * @default jobs from the `default` queue will be executed.\n */\n queue?: string\n randomID?: string\n req: PayloadRequest\n /**\n * By default, jobs are run in parallel.\n * If you want to run them in sequence, set this to true.\n */\n sequential?: boolean\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n where?: Where\n}\n\nexport type RunJobsResult = {\n jobStatus?: Record<string, RunJobResult>\n /**\n * If this is true, there for sure are no jobs remaining, regardless of the limit\n */\n noJobsRemaining?: boolean\n /**\n * Out of the jobs that were queried & processed (within the set limit), how many are remaining and retryable?\n */\n remainingJobsFromQueried: number\n}\n\nexport const runJobs = async (args: RunJobsArgs): Promise<RunJobsResult> => {\n const {\n id,\n allQueues = false,\n limit = 10,\n overrideAccess,\n processingOrder,\n queue = 'default',\n randomID,\n req,\n req: {\n payload,\n payload: {\n config: { jobs: jobsConfig },\n },\n },\n sequential,\n silent = false,\n where: whereFromProps,\n } = args\n console.log(`[${randomID}] 2 - runJobs started`, {\n id,\n allQueues,\n limit,\n queue,\n sequential,\n })\n\n if (!overrideAccess) {\n /**\n * By default, jobsConfig.access.run will be `defaultAccess` which is a function that returns `true` if the user is logged in.\n */\n const accessFn = jobsConfig?.access?.run ?? (() => true)\n const hasAccess = await accessFn({ req })\n if (!hasAccess) {\n throw new Forbidden(req.t)\n }\n }\n console.log(`[${randomID}] 3 - access check passed`)\n\n const and: Where[] = [\n {\n completedAt: {\n exists: false,\n },\n },\n {\n hasError: {\n not_equals: true,\n },\n },\n {\n processing: {\n equals: false,\n },\n },\n {\n or: [\n {\n waitUntil: {\n exists: false,\n },\n },\n {\n waitUntil: {\n less_than: getCurrentDate().toISOString(),\n },\n },\n ],\n },\n ]\n\n if (allQueues !== true) {\n and.push({\n queue: {\n equals: queue ?? 'default',\n },\n })\n }\n\n if (whereFromProps) {\n and.push(whereFromProps)\n }\n console.log(`[${args?.randomID}] 4`)\n\n // Only enforce concurrency controls if the feature is enabled\n if (jobsConfig.enableConcurrencyControl) {\n // Find currently running jobs with concurrency keys to enforce exclusive concurrency\n // Jobs with the same concurrencyKey should not run in parallel\n const runningJobsWithConcurrency = await payload.db.find({\n collection: jobsCollectionSlug,\n limit: 0,\n pagination: false,\n req: { transactionID: undefined },\n select: {\n concurrencyKey: true,\n },\n where: {\n and: [{ processing: { equals: true } }, { concurrencyKey: { exists: true } }],\n },\n })\n\n const runningConcurrencyKeys = new Set<string>()\n if (runningJobsWithConcurrency?.docs) {\n for (const doc of runningJobsWithConcurrency.docs) {\n const concurrencyKey = (doc as Job).concurrencyKey\n if (concurrencyKey) {\n runningConcurrencyKeys.add(concurrencyKey)\n }\n }\n }\n\n // Exclude jobs whose concurrencyKey is already running\n if (runningConcurrencyKeys.size > 0) {\n and.push({\n or: [\n // Jobs without a concurrency key can always run\n { concurrencyKey: { exists: false } },\n // Jobs with a concurrency key that is not currently running can run\n { concurrencyKey: { not_in: [...runningConcurrencyKeys] } },\n ],\n })\n }\n }\n\n console.log(`[${randomID}] 5 - concurrency control done, querying jobs`, {\n id,\n enableConcurrencyControl: jobsConfig.enableConcurrencyControl,\n })\n\n // Find all jobs and ensure we set job to processing: true as early as possible to reduce the chance of\n // the same job being picked up by another worker\n let jobs: Job[] = []\n\n if (id) {\n console.log(`[${randomID}] 5.1 - fetching single job by ID: ${id}`)\n\n // Only one job to run\n const job = await updateJob({\n id,\n data: {\n processing: true,\n },\n depth: jobsConfig.depth,\n disableTransaction: true,\n req,\n returning: true,\n })\n console.log(`[${randomID}] 5.2 - single job fetched`, { found: !!job })\n\n if (job) {\n jobs = [job]\n }\n } else {\n console.log(`[${randomID}] 5.3 - fetching multiple jobs with limit: ${limit}`)\n\n let defaultProcessingOrder: Sort =\n payload.collections[jobsCollectionSlug]?.config.defaultSort ?? 'createdAt'\n\n const processingOrderConfig = jobsConfig.processingOrder\n if (typeof processingOrderConfig === 'function') {\n defaultProcessingOrder = await processingOrderConfig(args)\n } else if (typeof processingOrderConfig === 'object' && !Array.isArray(processingOrderConfig)) {\n if (\n !allQueues &&\n queue &&\n processingOrderConfig.queues &&\n processingOrderConfig.queues[queue]\n ) {\n defaultProcessingOrder = processingOrderConfig.queues[queue]\n } else if (processingOrderConfig.default) {\n defaultProcessingOrder = processingOrderConfig.default\n }\n } else if (typeof processingOrderConfig === 'string') {\n defaultProcessingOrder = processingOrderConfig\n }\n\n console.log(`[${randomID}] 5.3.1 - using where query \"and\":`, and)\n\n const updatedDocs = await updateJobs({\n data: {\n processing: true,\n },\n debugID: randomID,\n depth: jobsConfig.depth,\n disableTransaction: true,\n limit,\n req,\n returning: true,\n sort: processingOrder ?? defaultProcessingOrder,\n where: { and },\n })\n console.log(`[${randomID}] 5.4 - multiple jobs fetched`, { count: updatedDocs?.length ?? 0 })\n if ((updatedDocs?.length ?? 0) > 0) {\n console.log(`[${randomID}] 5.5 - jobs found! fetched:`, { jobs: updatedDocs })\n }\n // Fetch ALL jobs using payload.db.find({})\n const allJobs = await payload.db.find({\n collection: jobsCollectionSlug,\n limit: 0,\n req,\n })\n console.log(`[${randomID}] 5.6 - all jobs fetched`, {\n allJobs: allJobs?.docs,\n count: allJobs?.totalDocs,\n })\n\n const anyRunnableJobs = allJobs?.docs?.some(\n (job: any) =>\n job?.processing === false &&\n job?.hasError === false &&\n !job?.completedAt &&\n !job?.waitUntil,\n )\n if (anyRunnableJobs && updatedDocs?.length === 0) {\n console.log(`[${randomID}] 5.6.1 - potential issue here.`)\n }\n\n if (updatedDocs) {\n jobs = updatedDocs\n }\n }\n console.log(`[${randomID}] 6 - jobs to process`, {\n count: jobs.length,\n jobIds: jobs.map((j) => j.id),\n })\n\n if (!jobs.length) {\n console.log(`[${randomID}] 7 - no jobs found, returning early`)\n\n return {\n noJobsRemaining: true,\n remainingJobsFromQueried: 0,\n }\n }\n\n // Only handle concurrency deduplication if the feature is enabled\n if (jobsConfig.enableConcurrencyControl) {\n // Handle the case where multiple jobs with the same concurrencyKey were picked up in the same batch\n // We should only run one job per concurrencyKey, release the others back to pending\n const seenConcurrencyKeys = new Set<string>()\n const jobsToRun: Job[] = []\n const jobsToRelease: Job[] = []\n\n for (const job of jobs) {\n if (job.concurrencyKey) {\n if (seenConcurrencyKeys.has(job.concurrencyKey)) {\n // This job has the same concurrencyKey as another job we're already running\n jobsToRelease.push(job)\n } else {\n seenConcurrencyKeys.add(job.concurrencyKey)\n jobsToRun.push(job)\n }\n } else {\n jobsToRun.push(job)\n }\n }\n\n // Release duplicate concurrencyKey jobs back to pending state\n if (jobsToRelease.length > 0) {\n const releaseIds = jobsToRelease.map((job) => job.id)\n await updateJobs({\n data: { processing: false },\n debugID: randomID,\n disableTransaction: true,\n req,\n returning: false,\n where: { id: { in: releaseIds } },\n })\n }\n\n // Use only the filtered jobs going forward\n jobs = jobsToRun\n }\n console.log(`[${randomID}] 8 - concurrency dedup done`, { jobsToRun: jobs.length })\n\n if (!jobs.length) {\n console.log(`[${randomID}] 9 - all jobs were duplicates, returning early`)\n\n return {\n noJobsRemaining: false,\n remainingJobsFromQueried: 0,\n }\n }\n console.log(`[${randomID}] 10 - preparing to run ${jobs.length} jobs`)\n\n /**\n * Just for logging purposes, we want to know how many jobs are new and how many are existing (= already been tried).\n * This is only for logs - in the end we still want to run all jobs, regardless of whether they are new or existing.\n */\n const { existingJobs, newJobs } = jobs.reduce(\n (acc, job) => {\n if (job.totalTried > 0) {\n acc.existingJobs.push(job)\n } else {\n acc.newJobs.push(job)\n }\n return acc\n },\n { existingJobs: [] as Job[], newJobs: [] as Job[] },\n )\n\n console.log(`[${randomID}] 11 - job breakdown`, {\n existingJobCount: existingJobs.length,\n newJobCount: newJobs.length,\n })\n\n if (!silent || (typeof silent === 'object' && !silent.info)) {\n payload.logger.info({\n msg: `Running ${jobs.length} jobs.`,\n new: newJobs?.length,\n retrying: existingJobs?.length,\n })\n }\n\n const successfullyCompletedJobs: (number | string)[] = []\n\n const runSingleJob = async (\n job: Job,\n ): Promise<{\n id: number | string\n result: RunJobResult\n }> => {\n console.log(`[${randomID}] job:${job.id} - starting`, {\n taskSlug: job.taskSlug,\n totalTried: job.totalTried,\n workflowSlug: job.workflowSlug,\n })\n\n if (!job.workflowSlug && !job.taskSlug) {\n throw new Error('Job must have either a workflowSlug or a taskSlug')\n }\n const jobReq = isolateObjectProperty(req, 'transactionID')\n\n const workflowConfig: WorkflowConfig =\n job.workflowSlug && jobsConfig.workflows?.length\n ? jobsConfig.workflows.find(({ slug }) => slug === job.workflowSlug)!\n : {\n slug: 'singleTask',\n handler: async ({ job, tasks }) => {\n await tasks[job.taskSlug as string]!('1', {\n input: job.input,\n })\n },\n }\n\n if (!workflowConfig) {\n console.log(`[${randomID}] job:${job.id} - no workflow config found, skipping`)\n return {\n id: job.id,\n result: {\n status: 'error',\n },\n } // Skip jobs with no workflow configuration\n }\n\n try {\n const updateJob = getUpdateJobFunction(job, jobReq)\n\n // the runner will either be passed to the config\n // OR it will be a path, which we will need to import via eval to avoid\n // Next.js compiler dynamic import expression errors\n let workflowHandler: WorkflowHandler | WorkflowJSON\n if (\n typeof workflowConfig.handler === 'function' ||\n (typeof workflowConfig.handler === 'object' && Array.isArray(workflowConfig.handler))\n ) {\n workflowHandler = workflowConfig.handler\n } else {\n workflowHandler = await importHandlerPath<typeof workflowHandler>(workflowConfig.handler)\n\n if (!workflowHandler) {\n const jobLabel = job.workflowSlug || `Task: ${job.taskSlug}`\n const errorMessage = `Can't find runner while importing with the path ${workflowConfig.handler} in job type ${jobLabel}.`\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n payload.logger.error(errorMessage)\n }\n\n await updateJob({\n error: {\n error: errorMessage,\n },\n hasError: true,\n processing: false,\n })\n\n return {\n id: job.id,\n result: {\n status: 'error-reached-max-retries',\n },\n }\n }\n }\n\n if (typeof workflowHandler === 'function') {\n console.log(`[${randomID}] job:${job.id} - running function handler`)\n const result = await runJob({\n job,\n req: jobReq,\n silent,\n updateJob,\n workflowConfig,\n workflowHandler,\n })\n\n console.log(`[${randomID}] job:${job.id} - completed`, { status: result.status })\n\n if (result.status === 'success') {\n successfullyCompletedJobs.push(job.id)\n }\n\n return { id: job.id, result }\n } else {\n console.log(`[${randomID}] job:${job.id} - running JSON handler`)\n const result = await runJSONJob({\n job,\n req: jobReq,\n silent,\n updateJob,\n workflowConfig,\n workflowHandler,\n })\n\n console.log(`[${randomID}] job:${job.id} - completed`, { status: result.status })\n\n if (result.status === 'success') {\n successfullyCompletedJobs.push(job.id)\n }\n\n return { id: job.id, result }\n }\n } catch (error) {\n if (error instanceof JobCancelledError) {\n console.log(`[${randomID}] job:${job.id} - cancelled`, { message: error.message })\n if (\n !(job.error as Record<string, unknown> | undefined)?.cancelled ||\n !job.hasError ||\n job.processing ||\n job.completedAt ||\n job.waitUntil\n ) {\n // When using the local API to cancel jobs, the local API will update the job data for us to ensure the job is cancelled.\n // But when throwing a JobCancelledError within a task or workflow handler, we are responsible for updating the job data ourselves.\n await updateJob({\n id: job.id,\n data: {\n completedAt: null,\n error: {\n cancelled: true,\n message: error.message,\n },\n hasError: true,\n processing: false,\n waitUntil: null,\n },\n depth: 0,\n disableTransaction: true,\n req,\n returning: false,\n })\n }\n\n return {\n id: job.id,\n result: {\n status: 'error-reached-max-retries',\n },\n }\n }\n console.log(`[${randomID}] job:${job.id} - error thrown`, {\n error: error instanceof Error ? error.message : String(error),\n })\n throw error\n }\n }\n\n console.log(`[${randomID}] 12 - starting job execution`, {\n jobCount: jobs.length,\n sequential,\n })\n\n let resultsArray: { id: number | string; result: RunJobResult }[] = []\n if (sequential) {\n console.log(`[${randomID}] 12.1 - running jobs sequentially`)\n\n for (const job of jobs) {\n const result = await runSingleJob(job)\n if (result) {\n resultsArray.push(result)\n }\n }\n } else {\n console.log(`[${randomID}] 12.2 - running jobs in parallel`)\n const jobPromises = jobs.map(runSingleJob)\n resultsArray = (await Promise.all(jobPromises)) as {\n id: number | string\n result: RunJobResult\n }[]\n }\n\n console.log(`[${randomID}] 13 - all jobs executed`, {\n resultsCount: resultsArray.length,\n successfulCount: successfullyCompletedJobs.length,\n })\n\n if (jobsConfig.deleteJobOnComplete && successfullyCompletedJobs.length) {\n console.log(`[${randomID}] 14 - deleting completed jobs`, {\n count: successfullyCompletedJobs.length,\n })\n try {\n if (jobsConfig.runHooks) {\n await payload.delete({\n collection: jobsCollectionSlug,\n depth: 0, // can be 0 since we're not returning anything\n disableTransaction: true,\n where: { id: { in: successfullyCompletedJobs } },\n })\n } else {\n await payload.db.deleteMany({\n collection: jobsCollectionSlug,\n where: { id: { in: successfullyCompletedJobs } },\n })\n }\n } catch (err) {\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n payload.logger.error({\n err,\n msg: `Failed to delete jobs ${successfullyCompletedJobs.join(', ')} on complete`,\n })\n }\n }\n }\n\n const resultsObject: RunJobsResult['jobStatus'] = resultsArray.reduce(\n (acc, cur) => {\n if (cur !== null) {\n // Check if there's a valid result to include\n acc[cur.id] = cur.result\n }\n return acc\n },\n {} as Record<string, RunJobResult>,\n )\n\n let remainingJobsFromQueried = 0\n for (const jobID in resultsObject) {\n const jobResult = resultsObject[jobID]\n if (jobResult?.status === 'error') {\n remainingJobsFromQueried++ // Can be retried\n }\n }\n\n console.log(`[${randomID}] 15 - runJobs complete`, {\n remainingJobsFromQueried,\n successCount: successfullyCompletedJobs.length,\n totalProcessed: Object.keys(resultsObject).length,\n })\n\n return {\n jobStatus: resultsObject,\n remainingJobsFromQueried,\n }\n}\n"],"names":["Forbidden","isolateObjectProperty","jobsCollectionSlug","JobCancelledError","getCurrentDate","updateJob","updateJobs","getUpdateJobFunction","importHandlerPath","runJob","runJSONJob","runJobs","args","id","allQueues","limit","overrideAccess","processingOrder","queue","randomID","req","payload","config","jobs","jobsConfig","sequential","silent","where","whereFromProps","console","log","accessFn","access","run","hasAccess","t","and","completedAt","exists","hasError","not_equals","processing","equals","or","waitUntil","less_than","toISOString","push","enableConcurrencyControl","runningJobsWithConcurrency","db","find","collection","pagination","transactionID","undefined","select","concurrencyKey","runningConcurrencyKeys","Set","docs","doc","add","size","not_in","job","data","depth","disableTransaction","returning","found","defaultProcessingOrder","collections","defaultSort","processingOrderConfig","Array","isArray","queues","default","updatedDocs","debugID","sort","count","length","allJobs","totalDocs","anyRunnableJobs","some","jobIds","map","j","noJobsRemaining","remainingJobsFromQueried","seenConcurrencyKeys","jobsToRun","jobsToRelease","has","releaseIds","in","existingJobs","newJobs","reduce","acc","totalTried","existingJobCount","newJobCount","info","logger","msg","new","retrying","successfullyCompletedJobs","runSingleJob","taskSlug","workflowSlug","Error","jobReq","workflowConfig","workflows","slug","handler","tasks","input","result","status","workflowHandler","jobLabel","errorMessage","error","message","cancelled","String","jobCount","resultsArray","jobPromises","Promise","all","resultsCount","successfulCount","deleteJobOnComplete","runHooks","delete","deleteMany","err","join","resultsObject","cur","jobID","jobResult","successCount","totalProcessed","Object","keys","jobStatus"],"mappings":"AAOA,SAASA,SAAS,QAAQ,+BAA8B;AACxD,SAASC,qBAAqB,QAAQ,8CAA6C;AACnF,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,iBAAiB,QAAQ,wBAAuB;AACzD,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,SAAS,EAAEC,UAAU,QAAQ,+BAA8B;AACpE,SAASC,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,MAAM,QAAQ,oBAAmB;AAC1C,SAASC,UAAU,QAAQ,wBAAuB;AAkElD,OAAO,MAAMC,UAAU,OAAOC;IAC5B,MAAM,EACJC,EAAE,EACFC,YAAY,KAAK,EACjBC,QAAQ,EAAE,EACVC,cAAc,EACdC,eAAe,EACfC,QAAQ,SAAS,EACjBC,QAAQ,EACRC,GAAG,EACHA,KAAK,EACHC,OAAO,EACPA,SAAS,EACPC,QAAQ,EAAEC,MAAMC,UAAU,EAAE,EAC7B,EACF,EACDC,UAAU,EACVC,SAAS,KAAK,EACdC,OA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index.ts"],"sourcesContent":["import type { Job } from '../../../index.js'\nimport type { PayloadRequest, Sort, Where } from '../../../types/index.js'\nimport type { WorkflowJSON } from '../../config/types/workflowJSONTypes.js'\nimport type { WorkflowConfig, WorkflowHandler } from '../../config/types/workflowTypes.js'\nimport type { RunJobsSilent } from '../../localAPI.js'\nimport type { RunJobResult } from './runJob/index.js'\n\nimport { Forbidden } from '../../../errors/Forbidden.js'\nimport { isolateObjectProperty } from '../../../utilities/isolateObjectProperty.js'\nimport { jobsCollectionSlug } from '../../config/collection.js'\nimport { JobCancelledError } from '../../errors/index.js'\nimport { getCurrentDate } from '../../utilities/getCurrentDate.js'\nimport { updateJob, updateJobs } from '../../utilities/updateJob.js'\nimport { getUpdateJobFunction } from './runJob/getUpdateJobFunction.js'\nimport { importHandlerPath } from './runJob/importHandlerPath.js'\nimport { runJob } from './runJob/index.js'\nimport { runJSONJob } from './runJSONJob/index.js'\n\nexport type RunJobsArgs = {\n /**\n * If you want to run jobs from all queues, set this to true.\n * If you set this to true, the `queue` property will be ignored.\n *\n * @default false\n */\n allQueues?: boolean\n /**\n * ID of the job to run\n */\n id?: number | string\n /**\n * The maximum number of jobs to run in this invocation\n *\n * @default 10\n */\n limit?: number\n overrideAccess?: boolean\n /**\n * Adjust the job processing order\n *\n * FIFO would equal `createdAt` and LIFO would equal `-createdAt`.\n *\n * @default all jobs for all queues will be executed in FIFO order.\n */\n processingOrder?: Sort\n /**\n * If you want to run jobs from a specific queue, set this to the queue name.\n *\n * @default jobs from the `default` queue will be executed.\n */\n queue?: string\n req: PayloadRequest\n /**\n * By default, jobs are run in parallel.\n * If you want to run them in sequence, set this to true.\n */\n sequential?: boolean\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n where?: Where\n}\n\nexport type RunJobsResult = {\n jobStatus?: Record<string, RunJobResult>\n /**\n * If this is true, there for sure are no jobs remaining, regardless of the limit\n */\n noJobsRemaining?: boolean\n /**\n * Out of the jobs that were queried & processed (within the set limit), how many are remaining and retryable?\n */\n remainingJobsFromQueried: number\n}\n\nexport const runJobs = async (args: RunJobsArgs): Promise<RunJobsResult> => {\n const {\n id,\n allQueues = false,\n limit = 10,\n overrideAccess,\n processingOrder,\n queue = 'default',\n req,\n req: {\n payload,\n payload: {\n config: { jobs: jobsConfig },\n },\n },\n sequential,\n silent = false,\n where: whereFromProps,\n } = args\n\n if (!overrideAccess) {\n /**\n * By default, jobsConfig.access.run will be `defaultAccess` which is a function that returns `true` if the user is logged in.\n */\n const accessFn = jobsConfig?.access?.run ?? (() => true)\n const hasAccess = await accessFn({ req })\n if (!hasAccess) {\n throw new Forbidden(req.t)\n }\n }\n const and: Where[] = [\n {\n completedAt: {\n exists: false,\n },\n },\n {\n hasError: {\n not_equals: true,\n },\n },\n {\n processing: {\n equals: false,\n },\n },\n {\n or: [\n {\n waitUntil: {\n exists: false,\n },\n },\n {\n waitUntil: {\n less_than: getCurrentDate().toISOString(),\n },\n },\n ],\n },\n ]\n\n if (allQueues !== true) {\n and.push({\n queue: {\n equals: queue ?? 'default',\n },\n })\n }\n\n if (whereFromProps) {\n and.push(whereFromProps)\n }\n\n // Only enforce concurrency controls if the feature is enabled\n if (jobsConfig.enableConcurrencyControl) {\n // Find currently running jobs with concurrency keys to enforce exclusive concurrency\n // Jobs with the same concurrencyKey should not run in parallel\n const runningJobsWithConcurrency = await payload.db.find({\n collection: jobsCollectionSlug,\n limit: 0,\n pagination: false,\n req: { transactionID: undefined },\n select: {\n concurrencyKey: true,\n },\n where: {\n and: [{ processing: { equals: true } }, { concurrencyKey: { exists: true } }],\n },\n })\n\n const runningConcurrencyKeys = new Set<string>()\n if (runningJobsWithConcurrency?.docs) {\n for (const doc of runningJobsWithConcurrency.docs) {\n const concurrencyKey = (doc as Job).concurrencyKey\n if (concurrencyKey) {\n runningConcurrencyKeys.add(concurrencyKey)\n }\n }\n }\n\n // Exclude jobs whose concurrencyKey is already running\n if (runningConcurrencyKeys.size > 0) {\n and.push({\n or: [\n // Jobs without a concurrency key can always run\n { concurrencyKey: { exists: false } },\n // Jobs with a concurrency key that is not currently running can run\n { concurrencyKey: { not_in: [...runningConcurrencyKeys] } },\n ],\n })\n }\n }\n\n // Find all jobs and ensure we set job to processing: true as early as possible to reduce the chance of\n // the same job being picked up by another worker\n let jobs: Job[] = []\n\n if (id) {\n // Only one job to run\n const job = await updateJob({\n id,\n data: {\n processing: true,\n },\n depth: jobsConfig.depth,\n disableTransaction: true,\n req,\n returning: true,\n })\n if (job) {\n jobs = [job]\n }\n } else {\n let defaultProcessingOrder: Sort =\n payload.collections[jobsCollectionSlug]?.config.defaultSort ?? 'createdAt'\n\n const processingOrderConfig = jobsConfig.processingOrder\n if (typeof processingOrderConfig === 'function') {\n defaultProcessingOrder = await processingOrderConfig(args)\n } else if (typeof processingOrderConfig === 'object' && !Array.isArray(processingOrderConfig)) {\n if (\n !allQueues &&\n queue &&\n processingOrderConfig.queues &&\n processingOrderConfig.queues[queue]\n ) {\n defaultProcessingOrder = processingOrderConfig.queues[queue]\n } else if (processingOrderConfig.default) {\n defaultProcessingOrder = processingOrderConfig.default\n }\n } else if (typeof processingOrderConfig === 'string') {\n defaultProcessingOrder = processingOrderConfig\n }\n const updatedDocs = await updateJobs({\n data: {\n processing: true,\n },\n depth: jobsConfig.depth,\n disableTransaction: true,\n limit,\n req,\n returning: true,\n sort: processingOrder ?? defaultProcessingOrder,\n where: { and },\n })\n\n if (updatedDocs) {\n jobs = updatedDocs\n }\n }\n\n if (!jobs.length) {\n return {\n noJobsRemaining: true,\n remainingJobsFromQueried: 0,\n }\n }\n\n // Only handle concurrency deduplication if the feature is enabled\n if (jobsConfig.enableConcurrencyControl) {\n // Handle the case where multiple jobs with the same concurrencyKey were picked up in the same batch\n // We should only run one job per concurrencyKey, release the others back to pending\n const seenConcurrencyKeys = new Set<string>()\n const jobsToRun: Job[] = []\n const jobsToRelease: Job[] = []\n\n for (const job of jobs) {\n if (job.concurrencyKey) {\n if (seenConcurrencyKeys.has(job.concurrencyKey)) {\n // This job has the same concurrencyKey as another job we're already running\n jobsToRelease.push(job)\n } else {\n seenConcurrencyKeys.add(job.concurrencyKey)\n jobsToRun.push(job)\n }\n } else {\n jobsToRun.push(job)\n }\n }\n\n // Release duplicate concurrencyKey jobs back to pending state\n if (jobsToRelease.length > 0) {\n const releaseIds = jobsToRelease.map((job) => job.id)\n await updateJobs({\n data: { processing: false },\n disableTransaction: true,\n req,\n returning: false,\n where: { id: { in: releaseIds } },\n })\n }\n\n // Use only the filtered jobs going forward\n jobs = jobsToRun\n }\n\n if (!jobs.length) {\n return {\n noJobsRemaining: false,\n remainingJobsFromQueried: 0,\n }\n }\n\n /**\n * Just for logging purposes, we want to know how many jobs are new and how many are existing (= already been tried).\n * This is only for logs - in the end we still want to run all jobs, regardless of whether they are new or existing.\n */\n const { existingJobs, newJobs } = jobs.reduce(\n (acc, job) => {\n if (job.totalTried > 0) {\n acc.existingJobs.push(job)\n } else {\n acc.newJobs.push(job)\n }\n return acc\n },\n { existingJobs: [] as Job[], newJobs: [] as Job[] },\n )\n\n if (!silent || (typeof silent === 'object' && !silent.info)) {\n payload.logger.info({\n msg: `Running ${jobs.length} jobs.`,\n new: newJobs?.length,\n retrying: existingJobs?.length,\n })\n }\n\n const successfullyCompletedJobs: (number | string)[] = []\n\n const runSingleJob = async (\n job: Job,\n ): Promise<{\n id: number | string\n result: RunJobResult\n }> => {\n if (!job.workflowSlug && !job.taskSlug) {\n throw new Error('Job must have either a workflowSlug or a taskSlug')\n }\n const jobReq = isolateObjectProperty(req, 'transactionID')\n\n const workflowConfig: WorkflowConfig =\n job.workflowSlug && jobsConfig.workflows?.length\n ? jobsConfig.workflows.find(({ slug }) => slug === job.workflowSlug)!\n : {\n slug: 'singleTask',\n handler: async ({ job, tasks }) => {\n await tasks[job.taskSlug as string]!('1', {\n input: job.input,\n })\n },\n }\n\n if (!workflowConfig) {\n return {\n id: job.id,\n result: {\n status: 'error',\n },\n } // Skip jobs with no workflow configuration\n }\n\n try {\n const updateJob = getUpdateJobFunction(job, jobReq)\n\n // the runner will either be passed to the config\n // OR it will be a path, which we will need to import via eval to avoid\n // Next.js compiler dynamic import expression errors\n let workflowHandler: WorkflowHandler | WorkflowJSON\n if (\n typeof workflowConfig.handler === 'function' ||\n (typeof workflowConfig.handler === 'object' && Array.isArray(workflowConfig.handler))\n ) {\n workflowHandler = workflowConfig.handler\n } else {\n workflowHandler = await importHandlerPath<typeof workflowHandler>(workflowConfig.handler)\n\n if (!workflowHandler) {\n const jobLabel = job.workflowSlug || `Task: ${job.taskSlug}`\n const errorMessage = `Can't find runner while importing with the path ${workflowConfig.handler} in job type ${jobLabel}.`\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n payload.logger.error(errorMessage)\n }\n\n await updateJob({\n error: {\n error: errorMessage,\n },\n hasError: true,\n processing: false,\n })\n\n return {\n id: job.id,\n result: {\n status: 'error-reached-max-retries',\n },\n }\n }\n }\n\n if (typeof workflowHandler === 'function') {\n const result = await runJob({\n job,\n req: jobReq,\n silent,\n updateJob,\n workflowConfig,\n workflowHandler,\n })\n\n if (result.status === 'success') {\n successfullyCompletedJobs.push(job.id)\n }\n\n return { id: job.id, result }\n } else {\n const result = await runJSONJob({\n job,\n req: jobReq,\n silent,\n updateJob,\n workflowConfig,\n workflowHandler,\n })\n\n if (result.status === 'success') {\n successfullyCompletedJobs.push(job.id)\n }\n\n return { id: job.id, result }\n }\n } catch (error) {\n if (error instanceof JobCancelledError) {\n if (\n !(job.error as Record<string, unknown> | undefined)?.cancelled ||\n !job.hasError ||\n job.processing ||\n job.completedAt ||\n job.waitUntil\n ) {\n // When using the local API to cancel jobs, the local API will update the job data for us to ensure the job is cancelled.\n // But when throwing a JobCancelledError within a task or workflow handler, we are responsible for updating the job data ourselves.\n await updateJob({\n id: job.id,\n data: {\n completedAt: null,\n error: {\n cancelled: true,\n message: error.message,\n },\n hasError: true,\n processing: false,\n waitUntil: null,\n },\n depth: 0,\n disableTransaction: true,\n req,\n returning: false,\n })\n }\n\n return {\n id: job.id,\n result: {\n status: 'error-reached-max-retries',\n },\n }\n }\n throw error\n }\n }\n\n let resultsArray: { id: number | string; result: RunJobResult }[] = []\n if (sequential) {\n for (const job of jobs) {\n const result = await runSingleJob(job)\n if (result) {\n resultsArray.push(result)\n }\n }\n } else {\n const jobPromises = jobs.map(runSingleJob)\n resultsArray = (await Promise.all(jobPromises)) as {\n id: number | string\n result: RunJobResult\n }[]\n }\n\n if (jobsConfig.deleteJobOnComplete && successfullyCompletedJobs.length) {\n try {\n if (jobsConfig.runHooks) {\n await payload.delete({\n collection: jobsCollectionSlug,\n depth: 0, // can be 0 since we're not returning anything\n disableTransaction: true,\n where: { id: { in: successfullyCompletedJobs } },\n })\n } else {\n await payload.db.deleteMany({\n collection: jobsCollectionSlug,\n where: { id: { in: successfullyCompletedJobs } },\n })\n }\n } catch (err) {\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n payload.logger.error({\n err,\n msg: `Failed to delete jobs ${successfullyCompletedJobs.join(', ')} on complete`,\n })\n }\n }\n }\n\n const resultsObject: RunJobsResult['jobStatus'] = resultsArray.reduce(\n (acc, cur) => {\n if (cur !== null) {\n // Check if there's a valid result to include\n acc[cur.id] = cur.result\n }\n return acc\n },\n {} as Record<string, RunJobResult>,\n )\n\n let remainingJobsFromQueried = 0\n for (const jobID in resultsObject) {\n const jobResult = resultsObject[jobID]\n if (jobResult?.status === 'error') {\n remainingJobsFromQueried++ // Can be retried\n }\n }\n\n return {\n jobStatus: resultsObject,\n remainingJobsFromQueried,\n }\n}\n"],"names":["Forbidden","isolateObjectProperty","jobsCollectionSlug","JobCancelledError","getCurrentDate","updateJob","updateJobs","getUpdateJobFunction","importHandlerPath","runJob","runJSONJob","runJobs","args","id","allQueues","limit","overrideAccess","processingOrder","queue","req","payload","config","jobs","jobsConfig","sequential","silent","where","whereFromProps","accessFn","access","run","hasAccess","t","and","completedAt","exists","hasError","not_equals","processing","equals","or","waitUntil","less_than","toISOString","push","enableConcurrencyControl","runningJobsWithConcurrency","db","find","collection","pagination","transactionID","undefined","select","concurrencyKey","runningConcurrencyKeys","Set","docs","doc","add","size","not_in","job","data","depth","disableTransaction","returning","defaultProcessingOrder","collections","defaultSort","processingOrderConfig","Array","isArray","queues","default","updatedDocs","sort","length","noJobsRemaining","remainingJobsFromQueried","seenConcurrencyKeys","jobsToRun","jobsToRelease","has","releaseIds","map","in","existingJobs","newJobs","reduce","acc","totalTried","info","logger","msg","new","retrying","successfullyCompletedJobs","runSingleJob","workflowSlug","taskSlug","Error","jobReq","workflowConfig","workflows","slug","handler","tasks","input","result","status","workflowHandler","jobLabel","errorMessage","error","cancelled","message","resultsArray","jobPromises","Promise","all","deleteJobOnComplete","runHooks","delete","deleteMany","err","join","resultsObject","cur","jobID","jobResult","jobStatus"],"mappings":"AAOA,SAASA,SAAS,QAAQ,+BAA8B;AACxD,SAASC,qBAAqB,QAAQ,8CAA6C;AACnF,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,iBAAiB,QAAQ,wBAAuB;AACzD,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,SAAS,EAAEC,UAAU,QAAQ,+BAA8B;AACpE,SAASC,oBAAoB,QAAQ,mCAAkC;AACvE,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,MAAM,QAAQ,oBAAmB;AAC1C,SAASC,UAAU,QAAQ,wBAAuB;AAiElD,OAAO,MAAMC,UAAU,OAAOC;IAC5B,MAAM,EACJC,EAAE,EACFC,YAAY,KAAK,EACjBC,QAAQ,EAAE,EACVC,cAAc,EACdC,eAAe,EACfC,QAAQ,SAAS,EACjBC,GAAG,EACHA,KAAK,EACHC,OAAO,EACPA,SAAS,EACPC,QAAQ,EAAEC,MAAMC,UAAU,EAAE,EAC7B,EACF,EACDC,UAAU,EACVC,SAAS,KAA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D,OAAO;oBACPC,oBAAoB;oBACpBvC,OAAO;wBAAEb,IAAI;4BAAEyE,IAAIW;wBAA0B;oBAAE;gBACjD;YACF,OAAO;gBACL,MAAM7E,QAAQ2B,EAAE,CAAC6E,UAAU,CAAC;oBAC1B3E,YAAY/C;oBACZwB,OAAO;wBAAEb,IAAI;4BAAEyE,IAAIW;wBAA0B;oBAAE;gBACjD;YACF;QACF,EAAE,OAAO4B,KAAK;YACZ,IAAI,CAACpG,UAAW,OAAOA,WAAW,YAAY,CAACA,OAAOyF,KAAK,EAAG;gBAC5D9F,QAAQyE,MAAM,CAACqB,KAAK,CAAC;oBACnBW;oBACA/B,KAAK,CAAC,sBAAsB,EAAEG,0BAA0B6B,IAAI,CAAC,MAAM,YAAY,CAAC;gBAClF;YACF;QACF;IACF;IAEA,MAAMC,gBAA4CV,aAAa5B,MAAM,CACnE,CAACC,KAAKsC;QACJ,IAAIA,QAAQ,MAAM;YAChB,6CAA6C;YAC7CtC,GAAG,CAACsC,IAAInH,EAAE,CAAC,GAAGmH,IAAInB,MAAM;QAC1B;QACA,OAAOnB;IACT,GACA,CAAC;IAGH,IAAIX,2BAA2B;IAC/B,IAAK,MAAMkD,SAASF,cAAe;QACjC,MAAMG,YAAYH,aAAa,CAACE,MAAM;QACtC,IAAIC,WAAWpB,WAAW,SAAS;YACjC/B,4BAA2B,iBAAiB;QAC9C;IACF;IAEA,OAAO;QACLoD,WAAWJ;QACXhD;IACF;AACF,EAAC"}
|
|
@@ -2,7 +2,6 @@ import type { Job } from '../../index.js';
|
|
|
2
2
|
import type { PayloadRequest, Sort, Where } from '../../types/index.js';
|
|
3
3
|
type BaseArgs = {
|
|
4
4
|
data: Partial<Job>;
|
|
5
|
-
debugID?: string;
|
|
6
5
|
depth?: number;
|
|
7
6
|
disableTransaction?: boolean;
|
|
8
7
|
limit?: number;
|
|
@@ -31,6 +30,6 @@ export declare function updateJob(args: ArgsByID & BaseArgs): Promise<Job | unde
|
|
|
31
30
|
* Handles deciding whether it can used direct db methods or not, and if so,
|
|
32
31
|
* manually runs the afterRead hook that populates the `taskStatus` property.
|
|
33
32
|
*/
|
|
34
|
-
export declare function updateJobs({ id, data,
|
|
33
|
+
export declare function updateJobs({ id, data, depth, disableTransaction, limit: limitArg, req, returning, sort, where: whereArg, }: RunJobsArgs): Promise<Job[] | null>;
|
|
35
34
|
export {};
|
|
36
35
|
//# sourceMappingURL=updateJob.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateJob.d.ts","sourceRoot":"","sources":["../../../src/queues/utilities/updateJob.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAIvE,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IAClB,
|
|
1
|
+
{"version":3,"file":"updateJob.d.ts","sourceRoot":"","sources":["../../../src/queues/utilities/updateJob.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAIvE,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,cAAc,CAAA;IACnB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,KAAK,QAAQ,GAAG;IACd,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,IAAI,CAAC,EAAE,KAAK,CAAA;IACZ,KAAK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