payload 3.70.0 → 3.71.0-internal-debug.cd77e5d

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.
Files changed (87) hide show
  1. package/dist/collections/config/types.d.ts +9 -2
  2. package/dist/collections/config/types.d.ts.map +1 -1
  3. package/dist/collections/config/types.js.map +1 -1
  4. package/dist/collections/operations/local/find.d.ts +7 -3
  5. package/dist/collections/operations/local/find.d.ts.map +1 -1
  6. package/dist/collections/operations/local/find.js.map +1 -1
  7. package/dist/config/sanitize.d.ts.map +1 -1
  8. package/dist/config/sanitize.js +6 -8
  9. package/dist/config/sanitize.js.map +1 -1
  10. package/dist/config/types.d.ts +7 -0
  11. package/dist/config/types.d.ts.map +1 -1
  12. package/dist/config/types.js.map +1 -1
  13. package/dist/fields/baseFields/timezone/baseField.d.ts +4 -1
  14. package/dist/fields/baseFields/timezone/baseField.d.ts.map +1 -1
  15. package/dist/fields/baseFields/timezone/baseField.js +2 -1
  16. package/dist/fields/baseFields/timezone/baseField.js.map +1 -1
  17. package/dist/fields/config/client.d.ts.map +1 -1
  18. package/dist/fields/config/client.js +10 -0
  19. package/dist/fields/config/client.js.map +1 -1
  20. package/dist/fields/config/sanitize.d.ts.map +1 -1
  21. package/dist/fields/config/sanitize.js +14 -1
  22. package/dist/fields/config/sanitize.js.map +1 -1
  23. package/dist/fields/config/types.d.ts +33 -2
  24. package/dist/fields/config/types.d.ts.map +1 -1
  25. package/dist/fields/config/types.js.map +1 -1
  26. package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
  27. package/dist/fields/hooks/afterRead/index.js +1 -0
  28. package/dist/fields/hooks/afterRead/index.js.map +1 -1
  29. package/dist/fields/hooks/afterRead/promise.d.ts +9 -1
  30. package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
  31. package/dist/fields/hooks/afterRead/promise.js +15 -2
  32. package/dist/fields/hooks/afterRead/promise.js.map +1 -1
  33. package/dist/fields/hooks/afterRead/traverseFields.d.ts +9 -1
  34. package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
  35. package/dist/fields/hooks/afterRead/traverseFields.js +2 -1
  36. package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
  37. package/dist/index.bundled.d.ts +108 -23
  38. package/dist/index.d.ts +7 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -0
  41. package/dist/index.js.map +1 -1
  42. package/dist/queues/config/types/index.d.ts +8 -10
  43. package/dist/queues/config/types/index.d.ts.map +1 -1
  44. package/dist/queues/config/types/index.js.map +1 -1
  45. package/dist/queues/config/types/taskTypes.d.ts +16 -6
  46. package/dist/queues/config/types/taskTypes.d.ts.map +1 -1
  47. package/dist/queues/config/types/taskTypes.js.map +1 -1
  48. package/dist/queues/config/types/workflowTypes.d.ts +2 -2
  49. package/dist/queues/config/types/workflowTypes.d.ts.map +1 -1
  50. package/dist/queues/config/types/workflowTypes.js.map +1 -1
  51. package/dist/queues/errors/index.d.ts +5 -6
  52. package/dist/queues/errors/index.d.ts.map +1 -1
  53. package/dist/queues/errors/index.js +6 -5
  54. package/dist/queues/errors/index.js.map +1 -1
  55. package/dist/queues/operations/runJobs/index.d.ts +1 -1
  56. package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
  57. package/dist/queues/operations/runJobs/index.js +28 -6
  58. package/dist/queues/operations/runJobs/index.js.map +1 -1
  59. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.d.ts.map +1 -1
  60. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +5 -1
  61. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
  62. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js +1 -3
  63. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js.map +1 -1
  64. package/dist/types/index.d.ts +3 -1
  65. package/dist/types/index.d.ts.map +1 -1
  66. package/dist/types/index.js.map +1 -1
  67. package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
  68. package/dist/utilities/configToJSONSchema.js +14 -1
  69. package/dist/utilities/configToJSONSchema.js.map +1 -1
  70. package/dist/utilities/isolateObjectProperty.d.ts.map +1 -1
  71. package/dist/utilities/isolateObjectProperty.js +7 -4
  72. package/dist/utilities/isolateObjectProperty.js.map +1 -1
  73. package/dist/utilities/isolateObjectProperty.spec.js +120 -0
  74. package/dist/utilities/isolateObjectProperty.spec.js.map +1 -0
  75. package/dist/utilities/optionsAreEqual.d.ts +7 -0
  76. package/dist/utilities/optionsAreEqual.d.ts.map +1 -0
  77. package/dist/utilities/optionsAreEqual.js +35 -0
  78. package/dist/utilities/optionsAreEqual.js.map +1 -0
  79. package/dist/utilities/optionsAreEqual.spec.js +319 -0
  80. package/dist/utilities/optionsAreEqual.spec.js.map +1 -0
  81. package/dist/utilities/validateTimezones.d.ts +20 -0
  82. package/dist/utilities/validateTimezones.d.ts.map +1 -0
  83. package/dist/utilities/validateTimezones.js +76 -0
  84. package/dist/utilities/validateTimezones.js.map +1 -0
  85. package/dist/utilities/validateTimezones.spec.js +493 -0
  86. package/dist/utilities/validateTimezones.spec.js.map +1 -0
  87. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/queues/config/types/index.ts"],"sourcesContent":["import type { CollectionConfig, Job } from '../../../index.js'\nimport type { Payload, PayloadRequest, Sort } from '../../../types/index.js'\nimport type { RunJobsSilent } from '../../localAPI.js'\nimport type { RunJobsArgs } from '../../operations/runJobs/index.js'\nimport type { JobStats } from '../global.js'\nimport type { TaskConfig } from './taskTypes.js'\nimport type { WorkflowConfig } from './workflowTypes.js'\n\nexport type AutorunCronConfig = {\n /**\n * If you want to autoRUn 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 cron schedule for the job.\n * @default '* * * * *' (every minute).\n *\n * @example\n * ┌───────────── (optional) second (0 - 59)\n * │ ┌───────────── minute (0 - 59)\n * │ │ ┌───────────── hour (0 - 23)\n * │ │ │ ┌───────────── day of the month (1 - 31)\n * │ │ │ │ ┌───────────── month (1 - 12)\n * │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)\n * │ │ │ │ │ │\n * │ │ │ │ │ │\n * - '* 0 * * * *' every hour at minute 0\n * - '* 0 0 * * *' daily at midnight\n * - '* 0 0 * * 0' weekly at midnight on Sundays\n * - '* 0 0 1 * *' monthly at midnight on the 1st day of the month\n * - '* 0/5 * * * *' every 5 minutes\n * - '* * * * * *' every second\n */\n cron?: string\n /**\n * By default, the autorun will attempt to schedule jobs for tasks and workflows that have a `schedule` property, given\n * the queue name is the same.\n *\n * Set this to `true` to disable the scheduling of jobs automatically.\n *\n * @default false\n */\n disableScheduling?: boolean\n /**\n * The limit for the job. This can be overridden by the user. Defaults to 10.\n */\n limit?: number\n /**\n * The queue name for the job.\n *\n * @default 'default'\n */\n queue?: string\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}\n\nexport type RunJobAccessArgs = {\n req: PayloadRequest\n}\n\nexport type RunJobAccess = (args: RunJobAccessArgs) => boolean | Promise<boolean>\n\nexport type QueueJobAccessArgs = {\n req: PayloadRequest\n}\n\nexport type CancelJobAccessArgs = {\n req: PayloadRequest\n}\nexport type CancelJobAccess = (args: CancelJobAccessArgs) => boolean | Promise<boolean>\nexport type QueueJobAccess = (args: QueueJobAccessArgs) => boolean | Promise<boolean>\n\nexport type SanitizedJobsConfig = {\n /**\n * If set to `true`, the job system is enabled and a payload-jobs collection exists.\n * This property is automatically set during sanitization.\n */\n enabled?: boolean\n /**\n * If set to `true`, at least one task or workflow has scheduling enabled.\n * This property is automatically set during sanitization.\n */\n scheduling?: boolean\n /**\n * If set to `true`, a payload-job-stats global exists.\n * This property is automatically set during sanitization.\n */\n stats?: boolean\n} & JobsConfig\nexport type JobsConfig = {\n /**\n * Specify access control to determine who can interact with jobs.\n */\n access?: {\n /**\n * By default, all logged-in users can cancel jobs.\n */\n cancel?: CancelJobAccess\n /**\n * By default, all logged-in users can queue jobs.\n */\n queue?: QueueJobAccess\n /**\n * By default, all logged-in users can run jobs.\n */\n run?: RunJobAccess\n }\n /** Adds information about the parent job to the task log. This is useful for debugging and tracking the flow of tasks.\n *\n * In 4.0, this will default to `true`.\n *\n * @default false\n */\n addParentToTaskLog?: boolean\n /**\n * Allows you to configure cron jobs that automatically run queued jobs\n * at specified intervals. Note that this does not _queue_ new jobs - only\n * _runs_ jobs that are already in the specified queue.\n *\n * @remark this property should not be used on serverless platforms like Vercel\n */\n autoRun?:\n | ((payload: Payload) => AutorunCronConfig[] | Promise<AutorunCronConfig[]>)\n | AutorunCronConfig[]\n /**\n * Determine whether or not to delete a job after it has successfully completed.\n */\n deleteJobOnComplete?: boolean\n /**\n * Specify depth for retrieving jobs from the queue.\n * This should be as low as possible in order for job retrieval\n * to be as efficient as possible. Setting it to anything higher than\n * 0 will drastically affect performance, as less efficient database\n * queries will be used.\n *\n * @default 0\n * @deprecated - this will be removed in 4.0\n */\n depth?: number\n /**\n * Override any settings on the default Jobs collection. Accepts the default collection and allows you to return\n * a new collection.\n */\n jobsCollectionOverrides?: (args: { defaultJobsCollection: CollectionConfig }) => CollectionConfig\n /**\n * Adjust the job processing order using a Payload sort string. This can be set globally or per queue.\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?:\n | ((args: RunJobsArgs) => Promise<Sort> | Sort)\n | {\n default?: Sort\n queues: {\n [queue: string]: Sort\n }\n }\n | Sort\n /**\n * By default, the job system uses direct database calls for optimal performance.\n * If you added custom hooks to your jobs collection, you can set this to true to\n * use the standard Payload API for all job operations. This is discouraged, as it will\n * drastically affect performance.\n *\n * @default false\n * @deprecated - this will be removed in 4.0\n */\n runHooks?: boolean\n /**\n * A function that will be executed before Payload picks up jobs which are configured by the `jobs.autorun` function.\n * If this function returns true, jobs will be queried and picked up. If it returns false, jobs will not be run.\n * @default undefined - if this function is not defined, jobs will be run - as if () => true was passed.\n * @param payload\n * @returns boolean\n */\n shouldAutoRun?: (payload: Payload) => boolean | Promise<boolean>\n /**\n * Define all possible tasks here\n */\n tasks?: TaskConfig<any>[]\n /**\n * Define all the workflows here. Workflows orchestrate the flow of multiple tasks.\n */\n workflows?: WorkflowConfig<any>[]\n}\n\nexport type Queueable = {\n scheduleConfig: ScheduleConfig\n taskConfig?: TaskConfig\n // If not set, queue it immediately\n waitUntil?: Date\n workflowConfig?: WorkflowConfig\n}\n\ntype OptionalPromise<T> = Promise<T> | T\n\nexport type BeforeScheduleFn = (args: {\n defaultBeforeSchedule: BeforeScheduleFn\n /**\n * payload-job-stats global data\n */\n jobStats: JobStats\n queueable: Queueable\n req: PayloadRequest\n}) => OptionalPromise<{\n input?: object\n shouldSchedule: boolean\n waitUntil?: Date\n}>\n\nexport type AfterScheduleFn = (\n args: {\n defaultAfterSchedule: AfterScheduleFn\n /**\n * payload-job-stats global data. If the global does not exist, it will be null.\n */\n jobStats: JobStats | null\n queueable: Queueable\n req: PayloadRequest\n } & (\n | {\n error: Error\n job?: never\n status: 'error'\n }\n | {\n error?: never\n job: Job\n status: 'success'\n }\n | {\n error?: never\n job?: never\n /**\n * If the beforeSchedule hook returned `shouldSchedule: false`, this will be called with status `skipped`.\n */\n status: 'skipped'\n }\n ),\n) => OptionalPromise<void>\n\nexport type ScheduleConfig = {\n /**\n * The cron for scheduling the job.\n *\n * @example\n * ┌───────────── (optional) second (0 - 59)\n * │ ┌───────────── minute (0 - 59)\n * │ │ ┌───────────── hour (0 - 23)\n * │ │ │ ┌───────────── day of the month (1 - 31)\n * │ │ │ │ ┌───────────── month (1 - 12)\n * │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)\n * │ │ │ │ │ │\n * │ │ │ │ │ │\n * - '* 0 * * * *' every hour at minute 0\n * - '* 0 0 * * *' daily at midnight\n * - '* 0 0 * * 0' weekly at midnight on Sundays\n * - '* 0 0 1 * *' monthly at midnight on the 1st day of the month\n * - '* 0/5 * * * *' every 5 minutes\n * - '* * * * * *' every second\n */\n cron: string\n hooks?: {\n /**\n * Functions that will be executed after the job has been successfully scheduled.\n *\n * @default By default, global update?? Unless global update should happen before\n */\n afterSchedule?: AfterScheduleFn\n /**\n * Functions that will be executed before the job is scheduled.\n * You can use this to control whether or not the job should be scheduled, or what input\n * data should be passed to the job.\n *\n * @default By default, this has one function that returns { shouldSchedule: true } if the following conditions are met:\n * - There currently is no job of the same type in the specified queue that is currently running\n * - There currently is no job of the same type in the specified queue that is scheduled to run in the future\n * - There currently is no job of the same type in the specified queue that failed previously but can be retried\n */\n beforeSchedule?: BeforeScheduleFn\n }\n /**\n * Queue to which the scheduled job will be added.\n */\n queue: string\n}\n"],"names":[],"mappings":"AA8PA,WA4CC"}
1
+ {"version":3,"sources":["../../../../src/queues/config/types/index.ts"],"sourcesContent":["import type { CollectionConfig, Job } from '../../../index.js'\nimport type { MaybePromise, Payload, PayloadRequest, Sort } from '../../../types/index.js'\nimport type { RunJobsSilent } from '../../localAPI.js'\nimport type { RunJobsArgs } from '../../operations/runJobs/index.js'\nimport type { JobStats } from '../global.js'\nimport type { TaskConfig } from './taskTypes.js'\nimport type { WorkflowConfig } from './workflowTypes.js'\n\nexport type AutorunCronConfig = {\n /**\n * If you want to autoRUn 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 cron schedule for the job.\n * @default '* * * * *' (every minute).\n *\n * @example\n * ┌───────────── (optional) second (0 - 59)\n * │ ┌───────────── minute (0 - 59)\n * │ │ ┌───────────── hour (0 - 23)\n * │ │ │ ┌───────────── day of the month (1 - 31)\n * │ │ │ │ ┌───────────── month (1 - 12)\n * │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)\n * │ │ │ │ │ │\n * │ │ │ │ │ │\n * - '* 0 * * * *' every hour at minute 0\n * - '* 0 0 * * *' daily at midnight\n * - '* 0 0 * * 0' weekly at midnight on Sundays\n * - '* 0 0 1 * *' monthly at midnight on the 1st day of the month\n * - '* 0/5 * * * *' every 5 minutes\n * - '* * * * * *' every second\n */\n cron?: string\n /**\n * By default, the autorun will attempt to schedule jobs for tasks and workflows that have a `schedule` property, given\n * the queue name is the same.\n *\n * Set this to `true` to disable the scheduling of jobs automatically.\n *\n * @default false\n */\n disableScheduling?: boolean\n /**\n * The limit for the job. This can be overridden by the user. Defaults to 10.\n */\n limit?: number\n /**\n * The queue name for the job.\n *\n * @default 'default'\n */\n queue?: string\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}\n\nexport type RunJobAccessArgs = {\n req: PayloadRequest\n}\n\nexport type RunJobAccess = (args: RunJobAccessArgs) => MaybePromise<boolean>\n\nexport type QueueJobAccessArgs = {\n req: PayloadRequest\n}\n\nexport type CancelJobAccessArgs = {\n req: PayloadRequest\n}\nexport type CancelJobAccess = (args: CancelJobAccessArgs) => MaybePromise<boolean>\nexport type QueueJobAccess = (args: QueueJobAccessArgs) => MaybePromise<boolean>\n\nexport type SanitizedJobsConfig = {\n /**\n * If set to `true`, the job system is enabled and a payload-jobs collection exists.\n * This property is automatically set during sanitization.\n */\n enabled?: boolean\n /**\n * If set to `true`, at least one task or workflow has scheduling enabled.\n * This property is automatically set during sanitization.\n */\n scheduling?: boolean\n /**\n * If set to `true`, a payload-job-stats global exists.\n * This property is automatically set during sanitization.\n */\n stats?: boolean\n} & JobsConfig\nexport type JobsConfig = {\n /**\n * Specify access control to determine who can interact with jobs.\n */\n access?: {\n /**\n * By default, all logged-in users can cancel jobs.\n */\n cancel?: CancelJobAccess\n /**\n * By default, all logged-in users can queue jobs.\n */\n queue?: QueueJobAccess\n /**\n * By default, all logged-in users can run jobs.\n */\n run?: RunJobAccess\n }\n /** Adds information about the parent job to the task log. This is useful for debugging and tracking the flow of tasks.\n *\n * In 4.0, this will default to `true`.\n *\n * @default false\n */\n addParentToTaskLog?: boolean\n /**\n * Allows you to configure cron jobs that automatically run queued jobs\n * at specified intervals. Note that this does not _queue_ new jobs - only\n * _runs_ jobs that are already in the specified queue.\n *\n * @remark this property should not be used on serverless platforms like Vercel\n */\n autoRun?: ((payload: Payload) => MaybePromise<AutorunCronConfig[]>) | AutorunCronConfig[]\n /**\n * Determine whether or not to delete a job after it has successfully completed.\n */\n deleteJobOnComplete?: boolean\n /**\n * Specify depth for retrieving jobs from the queue.\n * This should be as low as possible in order for job retrieval\n * to be as efficient as possible. Setting it to anything higher than\n * 0 will drastically affect performance, as less efficient database\n * queries will be used.\n *\n * @default 0\n * @deprecated - this will be removed in 4.0\n */\n depth?: number\n /**\n * Override any settings on the default Jobs collection. Accepts the default collection and allows you to return\n * a new collection.\n */\n jobsCollectionOverrides?: (args: { defaultJobsCollection: CollectionConfig }) => CollectionConfig\n /**\n * Adjust the job processing order using a Payload sort string. This can be set globally or per queue.\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?:\n | ((args: RunJobsArgs) => Promise<Sort> | Sort)\n | {\n default?: Sort\n queues: {\n [queue: string]: Sort\n }\n }\n | Sort\n /**\n * By default, the job system uses direct database calls for optimal performance.\n * If you added custom hooks to your jobs collection, you can set this to true to\n * use the standard Payload API for all job operations. This is discouraged, as it will\n * drastically affect performance.\n *\n * @default false\n * @deprecated - this will be removed in 4.0\n */\n runHooks?: boolean\n /**\n * A function that will be executed before Payload picks up jobs which are configured by the `jobs.autorun` function.\n * If this function returns true, jobs will be queried and picked up. If it returns false, jobs will not be run.\n * @default undefined - if this function is not defined, jobs will be run - as if () => true was passed.\n * @param payload\n * @returns boolean\n */\n shouldAutoRun?: (payload: Payload) => MaybePromise<boolean>\n /**\n * Define all possible tasks here\n */\n tasks?: TaskConfig<any>[]\n /**\n * Define all the workflows here. Workflows orchestrate the flow of multiple tasks.\n */\n workflows?: WorkflowConfig<any>[]\n}\n\nexport type Queueable = {\n scheduleConfig: ScheduleConfig\n taskConfig?: TaskConfig\n // If not set, queue it immediately\n waitUntil?: Date\n workflowConfig?: WorkflowConfig\n}\n\nexport type BeforeScheduleFn = (args: {\n defaultBeforeSchedule: BeforeScheduleFn\n /**\n * payload-job-stats global data\n */\n jobStats: JobStats\n queueable: Queueable\n req: PayloadRequest\n}) => MaybePromise<{\n input?: object\n shouldSchedule: boolean\n waitUntil?: Date\n}>\n\nexport type AfterScheduleFn = (\n args: {\n defaultAfterSchedule: AfterScheduleFn\n /**\n * payload-job-stats global data. If the global does not exist, it will be null.\n */\n jobStats: JobStats | null\n queueable: Queueable\n req: PayloadRequest\n } & (\n | {\n error: Error\n job?: never\n status: 'error'\n }\n | {\n error?: never\n job: Job\n status: 'success'\n }\n | {\n error?: never\n job?: never\n /**\n * If the beforeSchedule hook returned `shouldSchedule: false`, this will be called with status `skipped`.\n */\n status: 'skipped'\n }\n ),\n) => MaybePromise<void>\n\nexport type ScheduleConfig = {\n /**\n * The cron for scheduling the job.\n *\n * @example\n * ┌───────────── (optional) second (0 - 59)\n * │ ┌───────────── minute (0 - 59)\n * │ │ ┌───────────── hour (0 - 23)\n * │ │ │ ┌───────────── day of the month (1 - 31)\n * │ │ │ │ ┌───────────── month (1 - 12)\n * │ │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday)\n * │ │ │ │ │ │\n * │ │ │ │ │ │\n * - '* 0 * * * *' every hour at minute 0\n * - '* 0 0 * * *' daily at midnight\n * - '* 0 0 * * 0' weekly at midnight on Sundays\n * - '* 0 0 1 * *' monthly at midnight on the 1st day of the month\n * - '* 0/5 * * * *' every 5 minutes\n * - '* * * * * *' every second\n */\n cron: string\n hooks?: {\n /**\n * Functions that will be executed after the job has been successfully scheduled.\n *\n * @default By default, global update?? Unless global update should happen before\n */\n afterSchedule?: AfterScheduleFn\n /**\n * Functions that will be executed before the job is scheduled.\n * You can use this to control whether or not the job should be scheduled, or what input\n * data should be passed to the job.\n *\n * @default By default, this has one function that returns { shouldSchedule: true } if the following conditions are met:\n * - There currently is no job of the same type in the specified queue that is currently running\n * - There currently is no job of the same type in the specified queue that is scheduled to run in the future\n * - There currently is no job of the same type in the specified queue that failed previously but can be retried\n */\n beforeSchedule?: BeforeScheduleFn\n }\n /**\n * Queue to which the scheduled job will be added.\n */\n queue: string\n}\n"],"names":[],"mappings":"AA0PA,WA4CC"}
@@ -1,4 +1,4 @@
1
- import type { Field, Job, PayloadRequest, StringKeyOf, TypedJobs } from '../../../index.js';
1
+ import type { Field, Job, MaybePromise, PayloadRequest, StringKeyOf, TypedJobs } from '../../../index.js';
2
2
  import type { ScheduleConfig } from './index.js';
3
3
  import type { SingleTaskStatus } from './workflowTypes.js';
4
4
  export type TaskInputOutput = {
@@ -6,7 +6,13 @@ export type TaskInputOutput = {
6
6
  output: object;
7
7
  };
8
8
  export type TaskHandlerResult<TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput> = {
9
+ /**
10
+ * @deprecated Returning `state: 'failed'` is deprecated. Throw an error instead.
11
+ */
9
12
  errorMessage?: string;
13
+ /**
14
+ * @deprecated Returning `state: 'failed'` is deprecated. Throw an error instead.
15
+ */
10
16
  state: 'failed';
11
17
  } | {
12
18
  output: TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] ? TypedJobs['tasks'][TTaskSlugOrInputOutput]['output'] : TTaskSlugOrInputOutput extends TaskInputOutput ? TTaskSlugOrInputOutput['output'] : never;
@@ -29,7 +35,7 @@ export type TaskHandlerArgsNoInput<TWorkflowInput extends false | object = false
29
35
  job: Job<TWorkflowInput>;
30
36
  req: PayloadRequest;
31
37
  };
32
- export type TaskHandler<TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput, TWorkflowSlug extends keyof TypedJobs['workflows'] = string> = (args: TaskHandlerArgs<TTaskSlugOrInputOutput, TWorkflowSlug>) => Promise<TaskHandlerResult<TTaskSlugOrInputOutput>> | TaskHandlerResult<TTaskSlugOrInputOutput>;
38
+ export type TaskHandler<TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput, TWorkflowSlug extends keyof TypedJobs['workflows'] = string> = (args: TaskHandlerArgs<TTaskSlugOrInputOutput, TWorkflowSlug>) => MaybePromise<TaskHandlerResult<TTaskSlugOrInputOutput>>;
33
39
  /**
34
40
  * @todo rename to TaskSlug in 4.0, similar to CollectionSlug
35
41
  */
@@ -56,7 +62,6 @@ export type RunTaskFunction<TTaskSlug extends keyof TypedJobs['tasks']> = (taskI
56
62
  export type RunTaskFunctions = {
57
63
  [TTaskSlug in keyof TypedJobs['tasks']]: RunTaskFunction<TTaskSlug>;
58
64
  };
59
- type MaybePromise<T> = Promise<T> | T;
60
65
  export type RunInlineTaskFunction = <TTaskInput extends object, TTaskOutput extends object>(taskID: string, taskArgs: {
61
66
  input?: TTaskInput;
62
67
  /**
@@ -74,7 +79,13 @@ export type RunInlineTaskFunction = <TTaskInput extends object, TTaskOutput exte
74
79
  req: PayloadRequest;
75
80
  tasks: RunTaskFunctions;
76
81
  }) => MaybePromise<{
82
+ /**
83
+ * @deprecated Returning `state: 'failed'` is deprecated. Throw an error instead.
84
+ */
77
85
  errorMessage?: string;
86
+ /**
87
+ * @deprecated Returning `state: 'failed'` is deprecated. Throw an error instead.
88
+ */
78
89
  state: 'failed';
79
90
  } | {
80
91
  output: TTaskOutput;
@@ -92,8 +103,8 @@ export type TaskCallbackArgs = {
92
103
  };
93
104
  export type ShouldRestoreFn = (args: {
94
105
  taskStatus: SingleTaskStatus<string>;
95
- } & Omit<TaskCallbackArgs, 'taskStatus'>) => boolean | Promise<boolean>;
96
- export type TaskCallbackFn = (args: TaskCallbackArgs) => Promise<void> | void;
106
+ } & Omit<TaskCallbackArgs, 'taskStatus'>) => MaybePromise<boolean>;
107
+ export type TaskCallbackFn = (args: TaskCallbackArgs) => MaybePromise<void>;
97
108
  export type RetryConfig = {
98
109
  /**
99
110
  * This controls how many times the task should be retried if it fails.
@@ -200,5 +211,4 @@ export type TaskConfig<TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] |
200
211
  */
201
212
  slug: TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] ? TTaskSlugOrInputOutput : string;
202
213
  };
203
- export {};
204
214
  //# sourceMappingURL=taskTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"taskTypes.d.ts","sourceRoot":"","sources":["../../../../src/queues/config/types/taskTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE1D,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AACD,MAAM,MAAM,iBAAiB,CAC3B,sBAAsB,SAAS,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,eAAe,IAEvE;IACE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,QAAQ,CAAA;CAChB,GACD;IACE,MAAM,EAAE,sBAAsB,SAAS,MAAM,SAAS,CAAC,OAAO,CAAC,GAC3D,SAAS,CAAC,OAAO,CAAC,CAAC,sBAAsB,CAAC,CAAC,QAAQ,CAAC,GACpD,sBAAsB,SAAS,eAAe,GAC5C,sBAAsB,CAAC,QAAQ,CAAC,GAChC,KAAK,CAAA;IACX,KAAK,CAAC,EAAE,WAAW,CAAA;CACpB,CAAA;AAEL,MAAM,M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MAAM,WAAW,GAAG;IACxB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,OAAO,CAAC,EAAE;QACR;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAA;QACd;;;;;;;;;;;;;;;;;;;;;WAqBG;QACH,IAAI,EAAE,aAAa,GAAG,OAAO,CAAA;KAC9B,CAAA;IACD;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,EAAE,OAAO,GAAG,eAAe,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,UAAU,CACpB,sBAAsB,SAAS,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,eAAe,GAAG,QAAQ,IAClF;IACF;;;;;;;OAOG;IACH,OAAO,EAAE,MAAM,GAAG,WAAW,CAAC,sBAAsB,CAAC,CAAA;IACrD;;OAEG;IACH,WAAW,CAAC,EAAE,KAAK,EAAE,CAAA;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,cAAc,CAAA;IAC1B;;OAEG;IACH,YAAY,CAAC,EAAE,KAAK,EAAE,CAAA;IACtB;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAA;IAC1C;;OAEG;IACH,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAA;IAC3B;;OAEG;IACH,IAAI,EAAE,sBAAsB,SAAS,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,sBAAsB,GAAG,MAAM,CAAA;CAChG,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/queues/config/types/taskTypes.ts"],"sourcesContent":["import type { Field, Job, PayloadRequest, StringKeyOf, TypedJobs } from '../../../index.js'\nimport type { ScheduleConfig } from './index.js'\nimport type { SingleTaskStatus } from './workflowTypes.js'\n\nexport type TaskInputOutput = {\n input: object\n output: object\n}\nexport type TaskHandlerResult<\n TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput,\n> =\n | {\n errorMessage?: string\n state: 'failed'\n }\n | {\n output: TTaskSlugOrInputOutput extends keyof TypedJobs['tasks']\n ? TypedJobs['tasks'][TTaskSlugOrInputOutput]['output']\n : TTaskSlugOrInputOutput extends TaskInputOutput // Check if it's actually TaskInputOutput type\n ? TTaskSlugOrInputOutput['output']\n : never\n state?: 'succeeded'\n }\n\nexport type TaskHandlerArgs<\n TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput,\n TWorkflowSlug extends keyof TypedJobs['workflows'] = string,\n> = {\n /**\n * Use this function to run a sub-task from within another task.\n */\n inlineTask: RunInlineTaskFunction\n input: TTaskSlugOrInputOutput extends keyof TypedJobs['tasks']\n ? TypedJobs['tasks'][TTaskSlugOrInputOutput]['input']\n : TTaskSlugOrInputOutput extends TaskInputOutput // Check if it's actually TaskInputOutput type\n ? TTaskSlugOrInputOutput['input']\n : never\n job: Job<TWorkflowSlug>\n req: PayloadRequest\n tasks: RunTaskFunctions\n}\n\n/**\n * Inline tasks in JSON workflows have no input, as they can just get the input from job.taskStatus\n */\nexport type TaskHandlerArgsNoInput<TWorkflowInput extends false | object = false> = {\n job: Job<TWorkflowInput>\n req: PayloadRequest\n}\n\nexport type TaskHandler<\n TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput,\n TWorkflowSlug extends keyof TypedJobs['workflows'] = string,\n> = (\n args: TaskHandlerArgs<TTaskSlugOrInputOutput, TWorkflowSlug>,\n) => Promise<TaskHandlerResult<TTaskSlugOrInputOutput>> | TaskHandlerResult<TTaskSlugOrInputOutput>\n\n/**\n * @todo rename to TaskSlug in 4.0, similar to CollectionSlug\n */\nexport type TaskType = StringKeyOf<TypedJobs['tasks']>\n\n// Extracts the type of `input` corresponding to each task\nexport type TaskInput<T extends keyof TypedJobs['tasks']> = TypedJobs['tasks'][T]['input']\n\nexport type TaskOutput<T extends keyof TypedJobs['tasks']> = TypedJobs['tasks'][T]['output']\n\nexport type TaskHandlerResults = {\n [TTaskSlug in keyof TypedJobs['tasks']]: {\n [id: string]: TaskHandlerResult<TTaskSlug>\n }\n}\n\n// Helper type to create correct argument type for the function corresponding to each task.\nexport type RunTaskFunctionArgs<TTaskSlug extends keyof TypedJobs['tasks']> = {\n input?: TaskInput<TTaskSlug>\n /**\n * Specify the number of times that this task should be retried if it fails for any reason.\n * If this is undefined, the task will either inherit the retries from the workflow or have no retries.\n * If this is 0, the task will not be retried.\n *\n * @default By default, tasks are not retried and `retries` is `undefined`.\n */\n retries?: number | RetryConfig | undefined\n}\n\nexport type RunTaskFunction<TTaskSlug extends keyof TypedJobs['tasks']> = (\n taskID: string,\n taskArgs?: RunTaskFunctionArgs<TTaskSlug>,\n) => Promise<TaskOutput<TTaskSlug>>\n\nexport type RunTaskFunctions = {\n [TTaskSlug in keyof TypedJobs['tasks']]: RunTaskFunction<TTaskSlug>\n}\n\ntype MaybePromise<T> = Promise<T> | T\n\nexport type RunInlineTaskFunction = <TTaskInput extends object, TTaskOutput extends object>(\n taskID: string,\n taskArgs: {\n input?: TTaskInput\n /**\n * Specify the number of times that this task should be retried if it fails for any reason.\n * If this is undefined, the task will either inherit the retries from the workflow or have no retries.\n * If this is 0, the task will not be retried.\n *\n * @default By default, tasks are not retried and `retries` is `undefined`.\n */\n retries?: number | RetryConfig | undefined\n // This is the same as TaskHandler, but typed out explicitly in order to improve type inference\n task: (args: {\n inlineTask: RunInlineTaskFunction\n input: TTaskInput\n job: Job<any>\n req: PayloadRequest\n tasks: RunTaskFunctions\n }) => MaybePromise<\n | {\n errorMessage?: string\n state: 'failed'\n }\n | {\n output: TTaskOutput\n state?: 'succeeded'\n }\n >\n },\n) => Promise<TTaskOutput>\n\nexport type TaskCallbackArgs = {\n /**\n * Input data passed to the task\n */\n input?: object\n job: Job\n req: PayloadRequest\n taskStatus: null | SingleTaskStatus<string>\n}\n\nexport type ShouldRestoreFn = (\n args: { taskStatus: SingleTaskStatus<string> } & Omit<TaskCallbackArgs, 'taskStatus'>,\n) => boolean | Promise<boolean>\nexport type TaskCallbackFn = (args: TaskCallbackArgs) => Promise<void> | void\n\nexport type RetryConfig = {\n /**\n * This controls how many times the task should be retried if it fails.\n *\n * @default undefined - attempts are either inherited from the workflow retry config or set to 0.\n */\n attempts?: number\n /**\n * The backoff strategy to use when retrying the task. This determines how long to wait before retrying the task.\n *\n * If this is set on a single task, the longest backoff time of a task will determine the time until the entire workflow is retried.\n */\n backoff?: {\n /**\n * Base delay between running jobs in ms\n */\n delay?: number\n /**\n * @default fixed\n *\n * The backoff strategy to use when retrying the task. This determines how long to wait before retrying the task.\n * If fixed (default) is used, the delay will be the same between each retry.\n *\n * If exponential is used, the delay will increase exponentially with each retry.\n *\n * @example\n * delay = 1000\n * attempts = 3\n * type = 'fixed'\n *\n * The task will be retried 3 times with a delay of 1000ms between each retry.\n *\n * @example\n * delay = 1000\n * attempts = 3\n * type = 'exponential'\n *\n * The task will be retried 3 times with a delay of 1000ms, 2000ms, and 4000ms between each retry.\n */\n type: 'exponential' | 'fixed'\n }\n /**\n * This controls whether the task output should be restored if the task previously succeeded and the workflow is being retried.\n *\n * If this is set to false, the task will be re-run even if it previously succeeded, ignoring the maximum number of retries.\n *\n * If this is set to true, the task will only be re-run if it previously failed.\n *\n * If this is a function, the return value of the function will determine whether the task should be re-run. This can be used for more complex restore logic,\n * e.g you may want to re-run a task up until a certain point and then restore it, or only re-run a task if the input has changed.\n *\n * @default true - the task output will be restored if the task previously succeeded.\n */\n shouldRestore?: boolean | ShouldRestoreFn\n}\n\nexport type TaskConfig<\n TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput = TaskType,\n> = {\n /**\n * The function that should be responsible for running the job.\n * You can either pass a string-based path to the job function file, or the job function itself.\n *\n * If you are using large dependencies within your job, you might prefer to pass the string path\n * because that will avoid bundling large dependencies in your Next.js app. Passing a string path is an advanced feature\n * that may require a sophisticated build pipeline in order to work.\n */\n handler: string | TaskHandler<TTaskSlugOrInputOutput>\n /**\n * Define the input field schema - payload will generate a type for this schema.\n */\n inputSchema?: Field[]\n /**\n * You can use interfaceName to change the name of the interface that is generated for this task. By default, this is \"Task\" + the capitalized task slug.\n */\n interfaceName?: string\n /**\n * Define a human-friendly label for this task.\n */\n label?: string\n /**\n * Function to be executed if the task fails.\n */\n onFail?: TaskCallbackFn\n /**\n * Function to be executed if the task succeeds.\n */\n onSuccess?: TaskCallbackFn\n /**\n * Define the output field schema - payload will generate a type for this schema.\n */\n outputSchema?: Field[]\n /**\n * Specify the number of times that this step should be retried if it fails.\n * If this is undefined, the task will either inherit the retries from the workflow or have no retries.\n * If this is 0, the task will not be retried.\n *\n * @default By default, tasks are not retried and `retries` is `undefined`.\n */\n retries?: number | RetryConfig | undefined\n /**\n * Allows automatically scheduling this task to run regularly at a specified interval.\n */\n schedule?: ScheduleConfig[]\n /**\n * Define a slug-based name for this job. This slug needs to be unique among both tasks and workflows.\n */\n slug: TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] ? TTaskSlugOrInputOutput : string\n}\n"],"names":[],"mappings":"AAwMA,WAoDC"}
1
+ {"version":3,"sources":["../../../../src/queues/config/types/taskTypes.ts"],"sourcesContent":["import type {\n Field,\n Job,\n MaybePromise,\n PayloadRequest,\n StringKeyOf,\n TypedJobs,\n} from '../../../index.js'\nimport type { ScheduleConfig } from './index.js'\nimport type { SingleTaskStatus } from './workflowTypes.js'\n\nexport type TaskInputOutput = {\n input: object\n output: object\n}\nexport type TaskHandlerResult<\n TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput,\n> =\n | {\n /**\n * @deprecated Returning `state: 'failed'` is deprecated. Throw an error instead.\n */\n errorMessage?: string\n /**\n * @deprecated Returning `state: 'failed'` is deprecated. Throw an error instead.\n */\n state: 'failed'\n }\n | {\n output: TTaskSlugOrInputOutput extends keyof TypedJobs['tasks']\n ? TypedJobs['tasks'][TTaskSlugOrInputOutput]['output']\n : TTaskSlugOrInputOutput extends TaskInputOutput // Check if it's actually TaskInputOutput type\n ? TTaskSlugOrInputOutput['output']\n : never\n state?: 'succeeded'\n }\n\nexport type TaskHandlerArgs<\n TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput,\n TWorkflowSlug extends keyof TypedJobs['workflows'] = string,\n> = {\n /**\n * Use this function to run a sub-task from within another task.\n */\n inlineTask: RunInlineTaskFunction\n input: TTaskSlugOrInputOutput extends keyof TypedJobs['tasks']\n ? TypedJobs['tasks'][TTaskSlugOrInputOutput]['input']\n : TTaskSlugOrInputOutput extends TaskInputOutput // Check if it's actually TaskInputOutput type\n ? TTaskSlugOrInputOutput['input']\n : never\n job: Job<TWorkflowSlug>\n req: PayloadRequest\n tasks: RunTaskFunctions\n}\n\n/**\n * Inline tasks in JSON workflows have no input, as they can just get the input from job.taskStatus\n */\nexport type TaskHandlerArgsNoInput<TWorkflowInput extends false | object = false> = {\n job: Job<TWorkflowInput>\n req: PayloadRequest\n}\n\nexport type TaskHandler<\n TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput,\n TWorkflowSlug extends keyof TypedJobs['workflows'] = string,\n> = (\n args: TaskHandlerArgs<TTaskSlugOrInputOutput, TWorkflowSlug>,\n) => MaybePromise<TaskHandlerResult<TTaskSlugOrInputOutput>>\n\n/**\n * @todo rename to TaskSlug in 4.0, similar to CollectionSlug\n */\nexport type TaskType = StringKeyOf<TypedJobs['tasks']>\n\n// Extracts the type of `input` corresponding to each task\nexport type TaskInput<T extends keyof TypedJobs['tasks']> = TypedJobs['tasks'][T]['input']\n\nexport type TaskOutput<T extends keyof TypedJobs['tasks']> = TypedJobs['tasks'][T]['output']\n\nexport type TaskHandlerResults = {\n [TTaskSlug in keyof TypedJobs['tasks']]: {\n [id: string]: TaskHandlerResult<TTaskSlug>\n }\n}\n\n// Helper type to create correct argument type for the function corresponding to each task.\nexport type RunTaskFunctionArgs<TTaskSlug extends keyof TypedJobs['tasks']> = {\n input?: TaskInput<TTaskSlug>\n /**\n * Specify the number of times that this task should be retried if it fails for any reason.\n * If this is undefined, the task will either inherit the retries from the workflow or have no retries.\n * If this is 0, the task will not be retried.\n *\n * @default By default, tasks are not retried and `retries` is `undefined`.\n */\n retries?: number | RetryConfig | undefined\n}\n\nexport type RunTaskFunction<TTaskSlug extends keyof TypedJobs['tasks']> = (\n taskID: string,\n taskArgs?: RunTaskFunctionArgs<TTaskSlug>,\n) => Promise<TaskOutput<TTaskSlug>>\n\nexport type RunTaskFunctions = {\n [TTaskSlug in keyof TypedJobs['tasks']]: RunTaskFunction<TTaskSlug>\n}\n\nexport type RunInlineTaskFunction = <TTaskInput extends object, TTaskOutput extends object>(\n taskID: string,\n taskArgs: {\n input?: TTaskInput\n /**\n * Specify the number of times that this task should be retried if it fails for any reason.\n * If this is undefined, the task will either inherit the retries from the workflow or have no retries.\n * If this is 0, the task will not be retried.\n *\n * @default By default, tasks are not retried and `retries` is `undefined`.\n */\n retries?: number | RetryConfig | undefined\n // This is the same as TaskHandler, but typed out explicitly in order to improve type inference\n task: (args: {\n inlineTask: RunInlineTaskFunction\n input: TTaskInput\n job: Job<any>\n req: PayloadRequest\n tasks: RunTaskFunctions\n }) => MaybePromise<\n | {\n /**\n * @deprecated Returning `state: 'failed'` is deprecated. Throw an error instead.\n */\n errorMessage?: string\n /**\n * @deprecated Returning `state: 'failed'` is deprecated. Throw an error instead.\n */\n state: 'failed'\n }\n | {\n output: TTaskOutput\n state?: 'succeeded'\n }\n >\n },\n) => Promise<TTaskOutput>\n\nexport type TaskCallbackArgs = {\n /**\n * Input data passed to the task\n */\n input?: object\n job: Job\n req: PayloadRequest\n taskStatus: null | SingleTaskStatus<string>\n}\n\nexport type ShouldRestoreFn = (\n args: { taskStatus: SingleTaskStatus<string> } & Omit<TaskCallbackArgs, 'taskStatus'>,\n) => MaybePromise<boolean>\nexport type TaskCallbackFn = (args: TaskCallbackArgs) => MaybePromise<void>\n\nexport type RetryConfig = {\n /**\n * This controls how many times the task should be retried if it fails.\n *\n * @default undefined - attempts are either inherited from the workflow retry config or set to 0.\n */\n attempts?: number\n /**\n * The backoff strategy to use when retrying the task. This determines how long to wait before retrying the task.\n *\n * If this is set on a single task, the longest backoff time of a task will determine the time until the entire workflow is retried.\n */\n backoff?: {\n /**\n * Base delay between running jobs in ms\n */\n delay?: number\n /**\n * @default fixed\n *\n * The backoff strategy to use when retrying the task. This determines how long to wait before retrying the task.\n * If fixed (default) is used, the delay will be the same between each retry.\n *\n * If exponential is used, the delay will increase exponentially with each retry.\n *\n * @example\n * delay = 1000\n * attempts = 3\n * type = 'fixed'\n *\n * The task will be retried 3 times with a delay of 1000ms between each retry.\n *\n * @example\n * delay = 1000\n * attempts = 3\n * type = 'exponential'\n *\n * The task will be retried 3 times with a delay of 1000ms, 2000ms, and 4000ms between each retry.\n */\n type: 'exponential' | 'fixed'\n }\n /**\n * This controls whether the task output should be restored if the task previously succeeded and the workflow is being retried.\n *\n * If this is set to false, the task will be re-run even if it previously succeeded, ignoring the maximum number of retries.\n *\n * If this is set to true, the task will only be re-run if it previously failed.\n *\n * If this is a function, the return value of the function will determine whether the task should be re-run. This can be used for more complex restore logic,\n * e.g you may want to re-run a task up until a certain point and then restore it, or only re-run a task if the input has changed.\n *\n * @default true - the task output will be restored if the task previously succeeded.\n */\n shouldRestore?: boolean | ShouldRestoreFn\n}\n\nexport type TaskConfig<\n TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] | TaskInputOutput = TaskType,\n> = {\n /**\n * The function that should be responsible for running the job.\n * You can either pass a string-based path to the job function file, or the job function itself.\n *\n * If you are using large dependencies within your job, you might prefer to pass the string path\n * because that will avoid bundling large dependencies in your Next.js app. Passing a string path is an advanced feature\n * that may require a sophisticated build pipeline in order to work.\n */\n handler: string | TaskHandler<TTaskSlugOrInputOutput>\n /**\n * Define the input field schema - payload will generate a type for this schema.\n */\n inputSchema?: Field[]\n /**\n * You can use interfaceName to change the name of the interface that is generated for this task. By default, this is \"Task\" + the capitalized task slug.\n */\n interfaceName?: string\n /**\n * Define a human-friendly label for this task.\n */\n label?: string\n /**\n * Function to be executed if the task fails.\n */\n onFail?: TaskCallbackFn\n /**\n * Function to be executed if the task succeeds.\n */\n onSuccess?: TaskCallbackFn\n /**\n * Define the output field schema - payload will generate a type for this schema.\n */\n outputSchema?: Field[]\n /**\n * Specify the number of times that this step should be retried if it fails.\n * If this is undefined, the task will either inherit the retries from the workflow or have no retries.\n * If this is 0, the task will not be retried.\n *\n * @default By default, tasks are not retried and `retries` is `undefined`.\n */\n retries?: number | RetryConfig | undefined\n /**\n * Allows automatically scheduling this task to run regularly at a specified interval.\n */\n schedule?: ScheduleConfig[]\n /**\n * Define a slug-based name for this job. This slug needs to be unique among both tasks and workflows.\n */\n slug: TTaskSlugOrInputOutput extends keyof TypedJobs['tasks'] ? TTaskSlugOrInputOutput : string\n}\n"],"names":[],"mappings":"AAyNA,WAoDC"}
@@ -1,5 +1,5 @@
1
1
  import type { Field } from '../../../fields/config/types.js';
2
- import type { Job, PayloadRequest, StringKeyOf, TypedCollection, TypedJobs } from '../../../index.js';
2
+ import type { Job, MaybePromise, PayloadRequest, StringKeyOf, TypedCollection, TypedJobs } from '../../../index.js';
3
3
  import type { TaskParent } from '../../operations/runJobs/runJob/getRunTaskFunction.js';
4
4
  import type { ScheduleConfig } from './index.js';
5
5
  import type { RetryConfig, RunInlineTaskFunction, RunTaskFunctions, TaskInput, TaskOutput, TaskType } from './taskTypes.js';
@@ -74,7 +74,7 @@ export type WorkflowHandler<TWorkflowSlugOrInput extends false | keyof TypedJobs
74
74
  job: Job<TWorkflowSlugOrInput>;
75
75
  req: PayloadRequest;
76
76
  tasks: RunTaskFunctions;
77
- }) => Promise<void>;
77
+ }) => MaybePromise<void>;
78
78
  export type SingleTaskStatus<T extends keyof TypedJobs['tasks']> = {
79
79
  complete: boolean;
80
80
  input: TaskInput<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"workflowTypes.d.ts","sourceRoot":"","sources":["../../../../src/queues/config/types/workflowTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,KAAK,EACV,GAAG,EACH,cAAc,EACd,WAAW,EACX,eAAe,EACf,SAAS,EACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uDAAuD,CAAA;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EACrB,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,QAAQ,EACT,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAE1D,MAAM,MAAM,MAAM,GAAG;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC5B;;OAEG;IACH,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,KAAK,EAAE,QAAQ,GAAG,WAAW,CAAA;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,CACjB,oBAAoB,SAAS,KAAK,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,KAAK,IAChF;IACF,WAAW,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;IAC3B,SAAS,EAAE,MAA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C,WAAW,CAAC,GAAG,MAAM,GAAG,KAAK,IAChF;IACF;;;;;;OAMG;IACH,OAAO,EACH,MAAM,GACN,eAAe,CAAC,oBAAoB,CAAC,GACrC,YAAY,CAAC,oBAAoB,SAAS,MAAM,GAAG,MAAM,GAAG,oBAAoB,CAAC,CAAA;IACrF;;OAEG;IACH,WAAW,CAAC,EAAE,KAAK,EAAE,CAAA;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAA;IAC1C;;OAEG;IACH,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAA;IAC3B;;OAEG;IACH,IAAI,EAAE,oBAAoB,SAAS,MAAM,SAAS,CAAC,WAAW,CAAC,GAAG,oBAAoB,GAAG,MAAM,CAAA;CAChG,CAAA"}
1
+ {"version":3,"file":"workflowTypes.d.ts","sourceRoot":"","sources":["../../../../src/queues/config/types/workflowTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAA;AAC5D,OAAO,KAAK,EACV,GAAG,EACH,YAAY,EACZ,cAAc,EACd,WAAW,EACX,eAAe,EACf,SAAS,EACV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uDAAuD,CAAA;AACvF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EACrB,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,QAAQ,EACT,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAE1D,MAAM,MAAM,MAAM,GAAG;IACnB,WAAW,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oB,GAAG,MAAM,CAAA;CAChG,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/queues/config/types/workflowTypes.ts"],"sourcesContent":["import type { Field } from '../../../fields/config/types.js'\nimport type {\n Job,\n PayloadRequest,\n StringKeyOf,\n TypedCollection,\n TypedJobs,\n} from '../../../index.js'\nimport type { TaskParent } from '../../operations/runJobs/runJob/getRunTaskFunction.js'\nimport type { ScheduleConfig } from './index.js'\nimport type {\n RetryConfig,\n RunInlineTaskFunction,\n RunTaskFunctions,\n TaskInput,\n TaskOutput,\n TaskType,\n} from './taskTypes.js'\nimport type { WorkflowJSON } from './workflowJSONTypes.js'\n\nexport type JobLog = {\n completedAt: string\n error?: unknown\n executedAt: string\n /**\n * ID added by the array field when the log is saved in the database\n */\n id: string\n input?: Record<string, any>\n output?: Record<string, any>\n /**\n * Sub-tasks (tasks that are run within a task) will have a parent task ID\n */\n parent?: TaskParent\n state: 'failed' | 'succeeded'\n taskID: string\n taskSlug: TaskType\n}\n\n/**\n * @deprecated - will be made private in 4.0. Please use the `Job` type instead.\n */\nexport type BaseJob<\n TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false,\n> = {\n completedAt?: null | string\n createdAt: string\n error?: unknown\n hasError?: boolean\n id: number | string\n input: TWorkflowSlugOrInput extends false\n ? object\n : TWorkflowSlugOrInput extends keyof TypedJobs['workflows']\n ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input']\n : TWorkflowSlugOrInput\n log?: JobLog[]\n meta?: {\n [key: string]: unknown\n /**\n * If true, this job was queued by the scheduling system.\n */\n scheduled?: boolean\n }\n processing?: boolean\n queue?: string\n taskSlug?: null | TaskType\n taskStatus: JobTaskStatus\n totalTried: number\n updatedAt: string\n waitUntil?: null | string\n workflowSlug?: null | WorkflowTypes\n}\n\n/**\n * @todo rename to WorkflowSlug in 4.0, similar to CollectionSlug\n */\nexport type WorkflowTypes = StringKeyOf<TypedJobs['workflows']>\n\n/**\n * @deprecated - will be removed in 4.0. Use `Job` type instead.\n */\nexport type RunningJob<TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] | object> = {\n input: TWorkflowSlugOrInput extends keyof TypedJobs['workflows']\n ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input']\n : TWorkflowSlugOrInput\n taskStatus: JobTaskStatus\n} & Omit<TypedCollection['payload-jobs'], 'input' | 'taskStatus'>\n\n/**\n * @deprecated - will be removed in 4.0. Use `Job` type instead.\n */\nexport type RunningJobSimple<TWorkflowInput extends object> = {\n input: TWorkflowInput\n} & TypedCollection['payload-jobs']\n\n// Simplified version of RunningJob that doesn't break TypeScript (TypeScript seems to stop evaluating RunningJob when it's too complex)\nexport type RunningJobFromTask<TTaskSlug extends keyof TypedJobs['tasks']> = {\n input: TypedJobs['tasks'][TTaskSlug]['input']\n} & TypedCollection['payload-jobs']\n\nexport type WorkflowHandler<\n TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false,\n> = (args: {\n inlineTask: RunInlineTaskFunction\n job: Job<TWorkflowSlugOrInput>\n req: PayloadRequest\n tasks: RunTaskFunctions\n}) => Promise<void>\n\nexport type SingleTaskStatus<T extends keyof TypedJobs['tasks']> = {\n complete: boolean\n input: TaskInput<T>\n output: TaskOutput<T>\n taskSlug: TaskType\n totalTried: number\n}\n\n/**\n * Task IDs mapped to their status\n */\nexport type JobTaskStatus = {\n // Wrap in taskSlug to improve typing\n [taskSlug in TaskType]: {\n [taskID: string]: SingleTaskStatus<taskSlug>\n }\n}\n\nexport type WorkflowConfig<\n TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false,\n> = {\n /**\n * You can either pass a string-based path to the workflow function file, or the workflow function itself.\n *\n * If you are using large dependencies within your workflow control flow, you might prefer to pass the string path\n * because that will avoid bundling large dependencies in your Next.js app. Passing a string path is an advanced feature\n * that may require a sophisticated build pipeline in order to work.\n */\n handler:\n | string\n | WorkflowHandler<TWorkflowSlugOrInput>\n | WorkflowJSON<TWorkflowSlugOrInput extends object ? string : TWorkflowSlugOrInput>\n /**\n * Define the input field schema - payload will generate a type for this schema.\n */\n inputSchema?: Field[]\n /**\n * You can use interfaceName to change the name of the interface that is generated for this workflow. By default, this is \"Workflow\" + the capitalized workflow slug.\n */\n interfaceName?: string\n /**\n * Define a human-friendly label for this workflow.\n */\n label?: string\n /**\n * Optionally, define the default queue name that this workflow should be tied to.\n * Defaults to \"default\".\n * Can be overridden when queuing jobs via Local API.\n */\n queue?: string\n /**\n * You can define `retries` on the workflow level, which will enforce that the workflow can only fail up to that number of retries. If a task does not have retries specified, it will inherit the retry count as specified on the workflow.\n *\n * You can specify `0` as `workflow` retries, which will disregard all `task` retry specifications and fail the entire workflow on any task failure.\n * You can leave `workflow` retries as undefined, in which case, the workflow will respect what each task dictates as their own retry count.\n *\n * @default undefined. By default, workflows retries are defined by their tasks\n */\n retries?: number | RetryConfig | undefined\n /**\n * Allows automatically scheduling this workflow to run regularly at a specified interval.\n */\n schedule?: ScheduleConfig[]\n /**\n * Define a slug-based name for this job.\n */\n slug: TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] ? TWorkflowSlugOrInput : string\n}\n"],"names":[],"mappings":"AA+HA,WAiDC"}
1
+ {"version":3,"sources":["../../../../src/queues/config/types/workflowTypes.ts"],"sourcesContent":["import type { Field } from '../../../fields/config/types.js'\nimport type {\n Job,\n MaybePromise,\n PayloadRequest,\n StringKeyOf,\n TypedCollection,\n TypedJobs,\n} from '../../../index.js'\nimport type { TaskParent } from '../../operations/runJobs/runJob/getRunTaskFunction.js'\nimport type { ScheduleConfig } from './index.js'\nimport type {\n RetryConfig,\n RunInlineTaskFunction,\n RunTaskFunctions,\n TaskInput,\n TaskOutput,\n TaskType,\n} from './taskTypes.js'\nimport type { WorkflowJSON } from './workflowJSONTypes.js'\n\nexport type JobLog = {\n completedAt: string\n error?: unknown\n executedAt: string\n /**\n * ID added by the array field when the log is saved in the database\n */\n id: string\n input?: Record<string, any>\n output?: Record<string, any>\n /**\n * Sub-tasks (tasks that are run within a task) will have a parent task ID\n */\n parent?: TaskParent\n state: 'failed' | 'succeeded'\n taskID: string\n taskSlug: TaskType\n}\n\n/**\n * @deprecated - will be made private in 4.0. Please use the `Job` type instead.\n */\nexport type BaseJob<\n TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false,\n> = {\n completedAt?: null | string\n createdAt: string\n error?: unknown\n hasError?: boolean\n id: number | string\n input: TWorkflowSlugOrInput extends false\n ? object\n : TWorkflowSlugOrInput extends keyof TypedJobs['workflows']\n ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input']\n : TWorkflowSlugOrInput\n log?: JobLog[]\n meta?: {\n [key: string]: unknown\n /**\n * If true, this job was queued by the scheduling system.\n */\n scheduled?: boolean\n }\n processing?: boolean\n queue?: string\n taskSlug?: null | TaskType\n taskStatus: JobTaskStatus\n totalTried: number\n updatedAt: string\n waitUntil?: null | string\n workflowSlug?: null | WorkflowTypes\n}\n\n/**\n * @todo rename to WorkflowSlug in 4.0, similar to CollectionSlug\n */\nexport type WorkflowTypes = StringKeyOf<TypedJobs['workflows']>\n\n/**\n * @deprecated - will be removed in 4.0. Use `Job` type instead.\n */\nexport type RunningJob<TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] | object> = {\n input: TWorkflowSlugOrInput extends keyof TypedJobs['workflows']\n ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input']\n : TWorkflowSlugOrInput\n taskStatus: JobTaskStatus\n} & Omit<TypedCollection['payload-jobs'], 'input' | 'taskStatus'>\n\n/**\n * @deprecated - will be removed in 4.0. Use `Job` type instead.\n */\nexport type RunningJobSimple<TWorkflowInput extends object> = {\n input: TWorkflowInput\n} & TypedCollection['payload-jobs']\n\n// Simplified version of RunningJob that doesn't break TypeScript (TypeScript seems to stop evaluating RunningJob when it's too complex)\nexport type RunningJobFromTask<TTaskSlug extends keyof TypedJobs['tasks']> = {\n input: TypedJobs['tasks'][TTaskSlug]['input']\n} & TypedCollection['payload-jobs']\n\nexport type WorkflowHandler<\n TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false,\n> = (args: {\n inlineTask: RunInlineTaskFunction\n job: Job<TWorkflowSlugOrInput>\n req: PayloadRequest\n tasks: RunTaskFunctions\n}) => MaybePromise<void>\n\nexport type SingleTaskStatus<T extends keyof TypedJobs['tasks']> = {\n complete: boolean\n input: TaskInput<T>\n output: TaskOutput<T>\n taskSlug: TaskType\n totalTried: number\n}\n\n/**\n * Task IDs mapped to their status\n */\nexport type JobTaskStatus = {\n // Wrap in taskSlug to improve typing\n [taskSlug in TaskType]: {\n [taskID: string]: SingleTaskStatus<taskSlug>\n }\n}\n\nexport type WorkflowConfig<\n TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false,\n> = {\n /**\n * You can either pass a string-based path to the workflow function file, or the workflow function itself.\n *\n * If you are using large dependencies within your workflow control flow, you might prefer to pass the string path\n * because that will avoid bundling large dependencies in your Next.js app. Passing a string path is an advanced feature\n * that may require a sophisticated build pipeline in order to work.\n */\n handler:\n | string\n | WorkflowHandler<TWorkflowSlugOrInput>\n | WorkflowJSON<TWorkflowSlugOrInput extends object ? string : TWorkflowSlugOrInput>\n /**\n * Define the input field schema - payload will generate a type for this schema.\n */\n inputSchema?: Field[]\n /**\n * You can use interfaceName to change the name of the interface that is generated for this workflow. By default, this is \"Workflow\" + the capitalized workflow slug.\n */\n interfaceName?: string\n /**\n * Define a human-friendly label for this workflow.\n */\n label?: string\n /**\n * Optionally, define the default queue name that this workflow should be tied to.\n * Defaults to \"default\".\n * Can be overridden when queuing jobs via Local API.\n */\n queue?: string\n /**\n * You can define `retries` on the workflow level, which will enforce that the workflow can only fail up to that number of retries. If a task does not have retries specified, it will inherit the retry count as specified on the workflow.\n *\n * You can specify `0` as `workflow` retries, which will disregard all `task` retry specifications and fail the entire workflow on any task failure.\n * You can leave `workflow` retries as undefined, in which case, the workflow will respect what each task dictates as their own retry count.\n *\n * @default undefined. By default, workflows retries are defined by their tasks\n */\n retries?: number | RetryConfig | undefined\n /**\n * Allows automatically scheduling this workflow to run regularly at a specified interval.\n */\n schedule?: ScheduleConfig[]\n /**\n * Define a slug-based name for this job.\n */\n slug: TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] ? TWorkflowSlugOrInput : string\n}\n"],"names":[],"mappings":"AAgIA,WAiDC"}
@@ -28,12 +28,11 @@ export declare class WorkflowError extends Error {
28
28
  args: WorkflowErrorArgs;
29
29
  constructor(args: WorkflowErrorArgs);
30
30
  }
31
+ /**
32
+ * Throw this error from within a task or workflow handler to cancel the job.
33
+ * Unlike failing a job (e.g. by throwing any other error), a cancelled job will not be retried.
34
+ */
31
35
  export declare class JobCancelledError extends Error {
32
- args: {
33
- job: Job;
34
- };
35
- constructor(args: {
36
- job: Job;
37
- });
36
+ constructor(message: string);
38
37
  }
39
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/queues/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC3E,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAC3E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oDAAoD,CAAA;AAEpF,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,IAAI,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,GAAG,CAAA;IACR,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,aAAa,EAAE,WAAW,CAAA;IAC1B,UAAU,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;IAC/B,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,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AChB,UAAU,EAAE,IAAI,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAA;IAC3C,cAAc,EAAE,cAAc,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,GAAG,EAAE,GAAG,CAAA;IACR,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,EAAE,cAAc,CAAA;CAC/B,CAAA;AAED,qBAAa,SAAU,SAAQ,KAAK;IAClC,IAAI,EAAE,aAAa,CAAA;gBACP,IAAI,EAAE,aAAa;CAIhC;AACD,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,EAAE,iBAAiB,CAAA;gBAEX,IAAI,EAAE,iBAAiB;CAIpC;AAED;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAG5B"}
@@ -12,11 +12,12 @@ export class WorkflowError extends Error {
12
12
  this.args = args;
13
13
  }
14
14
  }
15
- export class JobCancelledError extends Error {
16
- args;
17
- constructor(args){
18
- super(`Job ${args.job.id} was cancelled`);
19
- this.args = args;
15
+ /**
16
+ * Throw this error from within a task or workflow handler to cancel the job.
17
+ * Unlike failing a job (e.g. by throwing any other error), a cancelled job will not be retried.
18
+ */ export class JobCancelledError extends Error {
19
+ constructor(message){
20
+ super(message);
20
21
  }
21
22
  }
22
23
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queues/errors/index.ts"],"sourcesContent":["import type { Job, SingleTaskStatus, WorkflowConfig } from '../../index.js'\nimport type { RetryConfig, TaskConfig } from '../config/types/taskTypes.js'\nimport type { TaskParent } from '../operations/runJobs/runJob/getRunTaskFunction.js'\n\nexport type TaskErrorArgs = {\n executedAt: Date\n input?: object\n job: Job\n message: string\n output?: object\n parent?: TaskParent\n retriesConfig: RetryConfig\n taskConfig?: TaskConfig<string>\n taskID: string\n taskSlug: string\n taskStatus: null | SingleTaskStatus<string>\n workflowConfig: WorkflowConfig\n}\n\nexport type WorkflowErrorArgs = {\n job: Job\n message: string\n workflowConfig: WorkflowConfig\n}\n\nexport class TaskError extends Error {\n args: TaskErrorArgs\n constructor(args: TaskErrorArgs) {\n super(args.message)\n this.args = args\n }\n}\nexport class WorkflowError extends Error {\n args: WorkflowErrorArgs\n\n constructor(args: WorkflowErrorArgs) {\n super(args.message)\n this.args = args\n }\n}\n\nexport class JobCancelledError extends Error {\n args: {\n job: Job\n }\n\n constructor(args: { job: Job }) {\n super(`Job ${args.job.id} was cancelled`)\n this.args = args\n }\n}\n"],"names":["TaskError","Error","args","message","WorkflowError","JobCancelledError","job","id"],"mappings":"AAyBA,OAAO,MAAMA,kBAAkBC;IAC7BC,KAAmB;IACnB,YAAYA,IAAmB,CAAE;QAC/B,KAAK,CAACA,KAAKC,OAAO;QAClB,IAAI,CAACD,IAAI,GAAGA;IACd;AACF;AACA,OAAO,MAAME,sBAAsBH;IACjCC,KAAuB;IAEvB,YAAYA,IAAuB,CAAE;QACnC,KAAK,CAACA,KAAKC,OAAO;QAClB,IAAI,CAACD,IAAI,GAAGA;IACd;AACF;AAEA,OAAO,MAAMG,0BAA0BJ;IACrCC,KAEC;IAED,YAAYA,IAAkB,CAAE;QAC9B,KAAK,CAAC,CAAC,IAAI,EAAEA,KAAKI,GAAG,CAACC,EAAE,CAAC,cAAc,CAAC;QACxC,IAAI,CAACL,IAAI,GAAGA;IACd;AACF"}
1
+ {"version":3,"sources":["../../../src/queues/errors/index.ts"],"sourcesContent":["import type { Job, SingleTaskStatus, WorkflowConfig } from '../../index.js'\nimport type { RetryConfig, TaskConfig } from '../config/types/taskTypes.js'\nimport type { TaskParent } from '../operations/runJobs/runJob/getRunTaskFunction.js'\n\nexport type TaskErrorArgs = {\n executedAt: Date\n input?: object\n job: Job\n message: string\n output?: object\n parent?: TaskParent\n retriesConfig: RetryConfig\n taskConfig?: TaskConfig<string>\n taskID: string\n taskSlug: string\n taskStatus: null | SingleTaskStatus<string>\n workflowConfig: WorkflowConfig\n}\n\nexport type WorkflowErrorArgs = {\n job: Job\n message: string\n workflowConfig: WorkflowConfig\n}\n\nexport class TaskError extends Error {\n args: TaskErrorArgs\n constructor(args: TaskErrorArgs) {\n super(args.message)\n this.args = args\n }\n}\nexport class WorkflowError extends Error {\n args: WorkflowErrorArgs\n\n constructor(args: WorkflowErrorArgs) {\n super(args.message)\n this.args = args\n }\n}\n\n/**\n * Throw this error from within a task or workflow handler to cancel the job.\n * Unlike failing a job (e.g. by throwing any other error), a cancelled job will not be retried.\n */\nexport class JobCancelledError extends Error {\n constructor(message: string) {\n super(message)\n }\n}\n"],"names":["TaskError","Error","args","message","WorkflowError","JobCancelledError"],"mappings":"AAyBA,OAAO,MAAMA,kBAAkBC;IAC7BC,KAAmB;IACnB,YAAYA,IAAmB,CAAE;QAC/B,KAAK,CAACA,KAAKC,OAAO;QAClB,IAAI,CAACD,IAAI,GAAGA;IACd;AACF;AACA,OAAO,MAAME,sBAAsBH;IACjCC,KAAuB;IAEvB,YAAYA,IAAuB,CAAE;QACnC,KAAK,CAACA,KAAKC,OAAO;QAClB,IAAI,CAACD,IAAI,GAAGA;IACd;AACF;AAEA;;;CAGC,GACD,OAAO,MAAMG,0BAA0BJ;IACrC,YAAYE,OAAe,CAAE;QAC3B,KAAK,CAACA;IACR;AACF"}
@@ -54,7 +54,7 @@ export type RunJobsArgs = {
54
54
  export type RunJobsResult = {
55
55
  jobStatus?: Record<string, RunJobResult>;
56
56
  /**
57
- * If this is false, there for sure are no jobs remaining, regardless of the limit
57
+ * If this is true, there for sure are no jobs remaining, regardless of the limit
58
58
  */
59
59
  noJobsRemaining?: boolean;
60
60
  /**
@@ -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,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,CAwVtE,CAAA"}
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,CAqXtE,CAAA"}
@@ -114,6 +114,12 @@ export const runJobs = async (args)=>{
114
114
  jobs = updatedDocs;
115
115
  }
116
116
  }
117
+ if (!jobs.length) {
118
+ return {
119
+ noJobsRemaining: true,
120
+ remainingJobsFromQueried: 0
121
+ };
122
+ }
117
123
  /**
118
124
  * Just for logging purposes, we want to know how many jobs are new and how many are existing (= already been tried).
119
125
  * This is only for logs - in the end we still want to run all jobs, regardless of whether they are new or existing.
@@ -128,12 +134,6 @@ export const runJobs = async (args)=>{
128
134
  existingJobs: [],
129
135
  newJobs: []
130
136
  });
131
- if (!jobs.length) {
132
- return {
133
- noJobsRemaining: true,
134
- remainingJobsFromQueried: 0
135
- };
136
- }
137
137
  if (!silent || typeof silent === 'object' && !silent.info) {
138
138
  payload.logger.info({
139
139
  msg: `Running ${jobs.length} jobs.`,
@@ -230,6 +230,28 @@ export const runJobs = async (args)=>{
230
230
  }
231
231
  } catch (error) {
232
232
  if (error instanceof JobCancelledError) {
233
+ if (// @ts-expect-error error is not typed
234
+ !job.error?.cancelled || !job.hasError || job.processing || job.completedAt || job.waitUntil) {
235
+ // When using the local API to cancel jobs, the local API will update the job data for us to ensure the job is cancelled.
236
+ // But when throwing a JobCancelledError within a task or workflow handler, we are responsible for updating the job data ourselves.
237
+ await updateJob({
238
+ id: job.id,
239
+ data: {
240
+ completedAt: null,
241
+ error: {
242
+ cancelled: true,
243
+ message: error.message
244
+ },
245
+ hasError: true,
246
+ processing: false,
247
+ waitUntil: null
248
+ },
249
+ depth: 0,
250
+ disableTransaction: true,
251
+ req,
252
+ returning: false
253
+ });
254
+ }
233
255
  return {
234
256
  id: job.id,
235
257
  result: {
@@ -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 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 false, 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 // 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 /**\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 (!jobs.length) {\n return {\n noJobsRemaining: true,\n remainingJobsFromQueried: 0,\n }\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 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","job","data","depth","disableTransaction","returning","defaultProcessingOrder","collections","defaultSort","processingOrderConfig","Array","isArray","queues","default","updatedDocs","sort","existingJobs","newJobs","reduce","acc","totalTried","length","noJobsRemaining","remainingJobsFromQueried","info","logger","msg","new","retrying","successfullyCompletedJobs","runSingleJob","workflowSlug","taskSlug","Error","jobReq","workflowConfig","workflows","find","slug","handler","tasks","input","result","status","workflowHandler","jobLabel","errorMessage","error","resultsArray","jobPromises","map","Promise","all","deleteJobOnComplete","runHooks","delete","collection","in","db","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,KAAK,EACdC,OAAOC,cAAc,EACtB,GAAGf;IAEJ,IAAI,CAACI,gBAAg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R,MAAM,EAAE;QACtE,IAAI;YACF,IAAI1C,WAAW2E,QAAQ,EAAE;gBACvB,MAAM9E,QAAQ+E,MAAM,CAAC;oBACnBC,YAAYlG;oBACZ6C,OAAO;oBACPC,oBAAoB;oBACpBtB,OAAO;wBAAEb,IAAI;4BAAEwF,IAAI5B;wBAA0B;oBAAE;gBACjD;YACF,OAAO;gBACL,MAAMrD,QAAQkF,EAAE,CAACC,UAAU,CAAC;oBAC1BH,YAAYlG;oBACZwB,OAAO;wBAAEb,IAAI;4BAAEwF,IAAI5B;wBAA0B;oBAAE;gBACjD;YACF;QACF,EAAE,OAAO+B,KAAK;YACZ,IAAI,CAAC/E,UAAW,OAAOA,WAAW,YAAY,CAACA,OAAOkE,KAAK,EAAG;gBAC5DvE,QAAQiD,MAAM,CAACsB,KAAK,CAAC;oBACnBa;oBACAlC,KAAK,CAAC,sBAAsB,EAAEG,0BAA0BgC,IAAI,CAAC,MAAM,YAAY,CAAC;gBAClF;YACF;QACF;IACF;IAEA,MAAMC,gBAA4Cd,aAAa9B,MAAM,CACnE,CAACC,KAAK4C;QACJ,IAAIA,QAAQ,MAAM;YAChB,6CAA6C;YAC7C5C,GAAG,CAAC4C,IAAI9F,EAAE,CAAC,GAAG8F,IAAIrB,MAAM;QAC1B;QACA,OAAOvB;IACT,GACA,CAAC;IAGH,IAAII,2BAA2B;IAC/B,IAAK,MAAMyC,SAASF,cAAe;QACjC,MAAMG,YAAYH,aAAa,CAACE,MAAM;QACtC,IAAIC,WAAWtB,WAAW,SAAS;YACjCpB,4BAA2B,iBAAiB;QAC9C;IACF;IAEA,OAAO;QACL2C,WAAWJ;QACXvC;IACF;AACF,EAAC"}
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 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 // 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 /**\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 // @ts-expect-error error is not typed\n !job.error?.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","job","data","depth","disableTransaction","returning","defaultProcessingOrder","collections","defaultSort","processingOrderConfig","Array","isArray","queues","default","updatedDocs","sort","length","noJobsRemaining","remainingJobsFromQueried","existingJobs","newJobs","reduce","acc","totalTried","info","logger","msg","new","retrying","successfullyCompletedJobs","runSingleJob","workflowSlug","taskSlug","Error","jobReq","workflowConfig","workflows","find","slug","handler","tasks","input","result","status","workflowHandler","jobLabel","errorMessage","error","cancelled","message","resultsArray","jobPromises","map","Promise","all","deleteJobOnComplete","runHooks","delete","collection","in","db","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,KAAK,EACdC,OAAOC,cAAc,EACtB,GAAGf;IAEJ,IAAI,CAACI,gBAAgB;QACnB;;KAEC,GACD,MAAMY,WAAWL,YAAYM,QAAQC,OAAQ,CAAA,IAAM,IAAG;QACtD,MAAMC,YAAY,MAAMH,SAAS;YAAET;QAAI;QACvC,IAAI,CAACY,WAAW;YACd,MAAM,IAAI/B,UAAUmB,IAAIa,CAAC;QAC3B;IACF;IACA,MAAMC,MAAe;QACnB;YACEC,aAAa;gBACXC,QAAQ;YACV;QACF;QACA;YACEC,UAAU;gBACRC,YAAY;YACd;QACF;QACA;YACEC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../../../src/queues/operations/runJobs/runJob/getRunTaskFunction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC5E,OAAO,KAAK,EAEV,qBAAqB,EAErB,gBAAgB,EAKjB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,KAAK,EAGV,cAAc,EAEf,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAQlE,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,SAAS,SAAS,OAAO,OACrD,GAAG,kBACQ,cAAc,OACzB,cAAc,YACT,SAAS,aACR,iBAAiB,WACnB,UAAU,KAClB,SAAS,SAAS,IAAI,GAAG,qBAAqB,GAAG,gBAwLnD,CAAA"}
1
+ {"version":3,"file":"getRunTaskFunction.d.ts","sourceRoot":"","sources":["../../../../../src/queues/operations/runJobs/runJob/getRunTaskFunction.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC5E,OAAO,KAAK,EAEV,qBAAqB,EAErB,gBAAgB,EAKjB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,KAAK,EAGV,cAAc,EAEf,MAAM,wCAAwC,CAAA;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAQlE,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,SAAS,SAAS,OAAO,OACrD,GAAG,kBACQ,cAAc,OACzB,cAAc,YACT,SAAS,aACR,iBAAiB,WACnB,UAAU,KAClB,SAAS,SAAS,IAAI,GAAG,qBAAqB,GAAG,gBA4LnD,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import ObjectIdImport from 'bson-objectid';
2
- import { TaskError } from '../../../errors/index.js';
2
+ import { JobCancelledError, TaskError } from '../../../errors/index.js';
3
3
  import { getCurrentDate } from '../../../utilities/getCurrentDate.js';
4
4
  import { getTaskHandlerFromConfig } from './importHandlerPath.js';
5
5
  const ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport;
@@ -76,6 +76,10 @@ export const getRunTaskFunction = (job, workflowConfig, req, isInline, updateJob
76
76
  })
77
77
  });
78
78
  } catch (err) {
79
+ if (err instanceof JobCancelledError) {
80
+ // Re-throw JobCancelledError to be handled by the top-level error handler
81
+ throw err;
82
+ }
79
83
  throw new TaskError({
80
84
  executedAt,
81
85
  input: input,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/queues/operations/runJobs/runJob/getRunTaskFunction.ts"],"sourcesContent":["import ObjectIdImport from 'bson-objectid'\n\nimport type { Job } from '../../../../index.js'\nimport type { JsonObject, PayloadRequest } from '../../../../types/index.js'\nimport type {\n RetryConfig,\n RunInlineTaskFunction,\n RunTaskFunction,\n RunTaskFunctions,\n TaskConfig,\n TaskHandler,\n TaskHandlerResult,\n TaskType,\n} from '../../../config/types/taskTypes.js'\nimport type {\n JobLog,\n SingleTaskStatus,\n WorkflowConfig,\n WorkflowTypes,\n} from '../../../config/types/workflowTypes.js'\nimport type { UpdateJobFunction } from './getUpdateJobFunction.js'\n\nimport { TaskError } from '../../../errors/index.js'\nimport { getCurrentDate } from '../../../utilities/getCurrentDate.js'\nimport { getTaskHandlerFromConfig } from './importHandlerPath.js'\n\nconst ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport\n\nexport type TaskParent = {\n taskID: string\n taskSlug: string\n}\n\nexport const getRunTaskFunction = <TIsInline extends boolean>(\n job: Job,\n workflowConfig: WorkflowConfig,\n req: PayloadRequest,\n isInline: TIsInline,\n updateJob: UpdateJobFunction,\n parent?: TaskParent,\n): TIsInline extends true ? RunInlineTaskFunction : RunTaskFunctions => {\n const jobConfig = req.payload.config.jobs\n\n const runTask: <TTaskSlug extends string>(\n taskSlug: TTaskSlug,\n ) => TTaskSlug extends 'inline' ? RunInlineTaskFunction : RunTaskFunction<TTaskSlug> = (\n taskSlug,\n ) =>\n (async (\n taskID: Parameters<RunInlineTaskFunction>[0],\n {\n input,\n retries,\n // Only available for inline tasks:\n task,\n }: Parameters<RunInlineTaskFunction>[1] & Parameters<RunTaskFunction<string>>[1],\n ) => {\n const executedAt = getCurrentDate()\n\n let taskConfig: TaskConfig | undefined\n if (!isInline) {\n taskConfig = (jobConfig.tasks?.length &&\n jobConfig.tasks.find((t) => t.slug === taskSlug)) as TaskConfig<string>\n\n if (!taskConfig) {\n throw new Error(`Task ${taskSlug} not found in workflow ${job.workflowSlug}`)\n }\n }\n\n const retriesConfigFromPropsNormalized =\n retries == undefined || retries == null\n ? {}\n : typeof retries === 'number'\n ? { attempts: retries }\n : retries\n const retriesConfigFromTaskConfigNormalized = taskConfig\n ? typeof taskConfig.retries === 'number'\n ? { attempts: taskConfig.retries }\n : taskConfig.retries\n : {}\n\n const finalRetriesConfig: RetryConfig = {\n ...retriesConfigFromTaskConfigNormalized,\n ...retriesConfigFromPropsNormalized, // Retry config from props takes precedence\n }\n\n const taskStatus: null | SingleTaskStatus<string> = job?.taskStatus?.[taskSlug]\n ? job.taskStatus[taskSlug][taskID]!\n : null\n\n // Handle restoration of task if it succeeded in a previous run\n if (taskStatus && taskStatus.complete === true) {\n let shouldRestore = true\n if (finalRetriesConfig?.shouldRestore === false) {\n shouldRestore = false\n } else if (typeof finalRetriesConfig?.shouldRestore === 'function') {\n shouldRestore = await finalRetriesConfig.shouldRestore({\n input,\n job,\n req,\n taskStatus,\n })\n }\n if (shouldRestore) {\n return taskStatus.output\n }\n }\n\n const runner = isInline\n ? (task as TaskHandler<TaskType>)\n : await getTaskHandlerFromConfig(taskConfig)\n\n if (!runner || typeof runner !== 'function') {\n throw new TaskError({\n executedAt,\n input,\n job,\n message: isInline\n ? `Inline task with ID ${taskID} does not have a valid handler.`\n : `Task with slug ${taskSlug} in workflow ${job.workflowSlug} does not have a valid handler.`,\n parent,\n retriesConfig: finalRetriesConfig,\n taskConfig,\n taskID,\n taskSlug,\n taskStatus,\n workflowConfig,\n })\n }\n\n let taskHandlerResult: TaskHandlerResult<string>\n let output: JsonObject | undefined = {}\n\n try {\n taskHandlerResult = await runner({\n inlineTask: getRunTaskFunction(job, workflowConfig, req, true, updateJob, {\n taskID,\n taskSlug,\n }),\n input,\n job: job as unknown as Job<WorkflowTypes>,\n req,\n tasks: getRunTaskFunction(job, workflowConfig, req, false, updateJob, {\n taskID,\n taskSlug,\n }),\n })\n } catch (err: any) {\n throw new TaskError({\n executedAt,\n input: input!,\n job,\n message: err.message || 'Task handler threw an error',\n output,\n parent,\n retriesConfig: finalRetriesConfig,\n taskConfig,\n taskID,\n taskSlug,\n taskStatus,\n workflowConfig,\n })\n }\n\n if (taskHandlerResult.state === 'failed') {\n throw new TaskError({\n executedAt,\n input: input!,\n job,\n message: taskHandlerResult.errorMessage ?? 'Task handler returned a failed state',\n output,\n parent,\n retriesConfig: finalRetriesConfig,\n taskConfig,\n taskID,\n taskSlug,\n taskStatus,\n workflowConfig,\n })\n } else {\n output = taskHandlerResult.output\n }\n\n if (taskConfig?.onSuccess) {\n await taskConfig.onSuccess({\n input,\n job,\n req,\n taskStatus,\n })\n }\n\n const newLogItem: JobLog = {\n id: new ObjectId().toHexString(),\n completedAt: getCurrentDate().toISOString(),\n executedAt: executedAt.toISOString(),\n input,\n output,\n parent: jobConfig.addParentToTaskLog ? parent : undefined,\n state: 'succeeded',\n taskID,\n taskSlug,\n }\n\n await updateJob({\n log: {\n $push: newLogItem,\n } as any,\n // Set to null to skip main row update on postgres. 2 => 1 db round trips\n updatedAt: null as any,\n })\n\n return output\n }) as any\n\n if (isInline) {\n return runTask('inline') as TIsInline extends true ? RunInlineTaskFunction : RunTaskFunctions\n } else {\n const tasks: RunTaskFunctions = {}\n for (const task of jobConfig.tasks ?? []) {\n tasks[task.slug] = runTask(task.slug) as RunTaskFunction<string>\n }\n return tasks as TIsInline extends true ? RunInlineTaskFunction : RunTaskFunctions\n }\n}\n"],"names":["ObjectIdImport","TaskError","getCurrentDate","getTaskHandlerFromConfig","ObjectId","default","getRunTaskFunction","job","workflowConfig","req","isInline","updateJob","parent","jobConfig","payload","config","jobs","runTask","taskSlug","taskID","input","retries","task","executedAt","taskConfig","tasks","length","find","t","slug","Error","workflowSlug","retriesConfigFromPropsNormalized","undefined","attempts","retriesConfigFromTaskConfigNormalized","finalRetriesConfig","taskStatus","complete","shouldRestore","output","runner","message","retriesConfig","taskHandlerResult","inlineTask","err","state","errorMessage","onSuccess","newLogItem","id","toHexString","completedAt","toISOString","addParentToTaskLog","log","$push","updatedAt"],"mappings":"AAAA,OAAOA,oBAAoB,gBAAe;AAsB1C,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,wBAAwB,QAAQ,yBAAwB;AAEjE,MAAMC,WAAW,aAAaJ,iBAAiBA,eAAeK,OAAO,GAAGL;AAOxE,OAAO,MAAMM,qBAAqB,CAChCC,KACAC,gBACAC,KACAC,UACAC,WACAC;IAEA,MAAMC,YAAYJ,IAAIK,OAAO,CAACC,MAAM,CAACC,IAAI;IAEzC,MAAMC,UAEiF,CACrFC,WAEC,OACCC,QACA,EACEC,KAAK,EACLC,OAAO,EACP,mCAAmC;QACnCC,IAAI,EAC0E;YAEhF,MAAMC,aAAarB;YAEnB,IAAIsB;YACJ,IAAI,CAACd,UAAU;gBACbc,aAAcX,UAAUY,KAAK,EAAEC,UAC7Bb,UAAUY,KAAK,CAACE,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAA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T;IAEF,IAAI9B,UAAU;QACZ,OAAOO,QAAQ;IACjB,OAAO;QACL,MAAMQ,QAA0B,CAAC;QACjC,KAAK,MAAMH,QAAQT,UAAUY,KAAK,IAAI,EAAE,CAAE;YACxCA,KAAK,CAACH,KAAKO,IAAI,CAAC,GAAGZ,QAAQK,KAAKO,IAAI;QACtC;QACA,OAAOJ;IACT;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/queues/operations/runJobs/runJob/getRunTaskFunction.ts"],"sourcesContent":["import ObjectIdImport from 'bson-objectid'\n\nimport type { Job } from '../../../../index.js'\nimport type { JsonObject, PayloadRequest } from '../../../../types/index.js'\nimport type {\n RetryConfig,\n RunInlineTaskFunction,\n RunTaskFunction,\n RunTaskFunctions,\n TaskConfig,\n TaskHandler,\n TaskHandlerResult,\n TaskType,\n} from '../../../config/types/taskTypes.js'\nimport type {\n JobLog,\n SingleTaskStatus,\n WorkflowConfig,\n WorkflowTypes,\n} from '../../../config/types/workflowTypes.js'\nimport type { UpdateJobFunction } from './getUpdateJobFunction.js'\n\nimport { JobCancelledError, TaskError } from '../../../errors/index.js'\nimport { getCurrentDate } from '../../../utilities/getCurrentDate.js'\nimport { getTaskHandlerFromConfig } from './importHandlerPath.js'\n\nconst ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport\n\nexport type TaskParent = {\n taskID: string\n taskSlug: string\n}\n\nexport const getRunTaskFunction = <TIsInline extends boolean>(\n job: Job,\n workflowConfig: WorkflowConfig,\n req: PayloadRequest,\n isInline: TIsInline,\n updateJob: UpdateJobFunction,\n parent?: TaskParent,\n): TIsInline extends true ? RunInlineTaskFunction : RunTaskFunctions => {\n const jobConfig = req.payload.config.jobs\n\n const runTask: <TTaskSlug extends string>(\n taskSlug: TTaskSlug,\n ) => TTaskSlug extends 'inline' ? RunInlineTaskFunction : RunTaskFunction<TTaskSlug> = (\n taskSlug,\n ) =>\n (async (\n taskID: Parameters<RunInlineTaskFunction>[0],\n {\n input,\n retries,\n // Only available for inline tasks:\n task,\n }: Parameters<RunInlineTaskFunction>[1] & Parameters<RunTaskFunction<string>>[1],\n ) => {\n const executedAt = getCurrentDate()\n\n let taskConfig: TaskConfig | undefined\n if (!isInline) {\n taskConfig = (jobConfig.tasks?.length &&\n jobConfig.tasks.find((t) => t.slug === taskSlug)) as TaskConfig<string>\n\n if (!taskConfig) {\n throw new Error(`Task ${taskSlug} not found in workflow ${job.workflowSlug}`)\n }\n }\n\n const retriesConfigFromPropsNormalized =\n retries == undefined || retries == null\n ? {}\n : typeof retries === 'number'\n ? { attempts: retries }\n : retries\n const retriesConfigFromTaskConfigNormalized = taskConfig\n ? typeof taskConfig.retries === 'number'\n ? { attempts: taskConfig.retries }\n : taskConfig.retries\n : {}\n\n const finalRetriesConfig: RetryConfig = {\n ...retriesConfigFromTaskConfigNormalized,\n ...retriesConfigFromPropsNormalized, // Retry config from props takes precedence\n }\n\n const taskStatus: null | SingleTaskStatus<string> = job?.taskStatus?.[taskSlug]\n ? job.taskStatus[taskSlug][taskID]!\n : null\n\n // Handle restoration of task if it succeeded in a previous run\n if (taskStatus && taskStatus.complete === true) {\n let shouldRestore = true\n if (finalRetriesConfig?.shouldRestore === false) {\n shouldRestore = false\n } else if (typeof finalRetriesConfig?.shouldRestore === 'function') {\n shouldRestore = await finalRetriesConfig.shouldRestore({\n input,\n job,\n req,\n taskStatus,\n })\n }\n if (shouldRestore) {\n return taskStatus.output\n }\n }\n\n const runner = isInline\n ? (task as TaskHandler<TaskType>)\n : await getTaskHandlerFromConfig(taskConfig)\n\n if (!runner || typeof runner !== 'function') {\n throw new TaskError({\n executedAt,\n input,\n job,\n message: isInline\n ? `Inline task with ID ${taskID} does not have a valid handler.`\n : `Task with slug ${taskSlug} in workflow ${job.workflowSlug} does not have a valid handler.`,\n parent,\n retriesConfig: finalRetriesConfig,\n taskConfig,\n taskID,\n taskSlug,\n taskStatus,\n workflowConfig,\n })\n }\n\n let taskHandlerResult: TaskHandlerResult<string>\n let output: JsonObject | undefined = {}\n\n try {\n taskHandlerResult = await runner({\n inlineTask: getRunTaskFunction(job, workflowConfig, req, true, updateJob, {\n taskID,\n taskSlug,\n }),\n input,\n job: job as unknown as Job<WorkflowTypes>,\n req,\n tasks: getRunTaskFunction(job, workflowConfig, req, false, updateJob, {\n taskID,\n taskSlug,\n }),\n })\n } catch (err: any) {\n if (err instanceof JobCancelledError) {\n // Re-throw JobCancelledError to be handled by the top-level error handler\n throw err\n }\n throw new TaskError({\n executedAt,\n input: input!,\n job,\n message: err.message || 'Task handler threw an error',\n output,\n parent,\n retriesConfig: finalRetriesConfig,\n taskConfig,\n taskID,\n taskSlug,\n taskStatus,\n workflowConfig,\n })\n }\n\n if (taskHandlerResult.state === 'failed') {\n throw new TaskError({\n executedAt,\n input: input!,\n job,\n message: taskHandlerResult.errorMessage ?? 'Task handler returned a failed state',\n output,\n parent,\n retriesConfig: finalRetriesConfig,\n taskConfig,\n taskID,\n taskSlug,\n taskStatus,\n workflowConfig,\n })\n } else {\n output = taskHandlerResult.output\n }\n\n if (taskConfig?.onSuccess) {\n await taskConfig.onSuccess({\n input,\n job,\n req,\n taskStatus,\n })\n }\n\n const newLogItem: JobLog = {\n id: new ObjectId().toHexString(),\n completedAt: getCurrentDate().toISOString(),\n executedAt: executedAt.toISOString(),\n input,\n output,\n parent: jobConfig.addParentToTaskLog ? parent : undefined,\n state: 'succeeded',\n taskID,\n taskSlug,\n }\n\n await updateJob({\n log: {\n $push: newLogItem,\n } as any,\n // Set to null to skip main row update on postgres. 2 => 1 db round trips\n updatedAt: null as any,\n })\n\n return output\n }) as any\n\n if (isInline) {\n return runTask('inline') as TIsInline extends true ? RunInlineTaskFunction : RunTaskFunctions\n } else {\n const tasks: RunTaskFunctions = {}\n for (const task of jobConfig.tasks ?? []) {\n tasks[task.slug] = runTask(task.slug) as RunTaskFunction<string>\n }\n return tasks as TIsInline extends true ? RunInlineTaskFunction : RunTaskFunctions\n }\n}\n"],"names":["ObjectIdImport","JobCancelledError","TaskError","getCurrentDate","getTaskHandlerFromConfig","ObjectId","default","getRunTaskFunction","job","workflowConfig","req","isInline","updateJob","parent","jobConfig","payload","config","jobs","runTask","taskSlug","taskID","input","retries","task","executedAt","taskConfig","tasks","length","find","t","slug","Error","workflowSlug","retriesConfigFromPropsNormalized","undefined","attempts","retriesConfigFromTaskConfigNormalized","finalRetriesConfig","taskStatus","complete","shouldRestore","output","runner","message","retriesConfig","taskHandlerResult","inlineTask","err","state","errorMessage","onSuccess","newLogItem","id","toHexString","completedAt","toISOString","addParentToTaskLog","log","$push","updatedAt"],"mappings":"AAAA,OAAOA,oBAAoB,gBAAe;AAsB1C,SAASC,iBAAiB,EAAEC,SAAS,QAAQ,2BAA0B;AACvE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,wBAAwB,QAAQ,yBAAwB;AAEjE,MAAMC,WAAW,aAAaL,iBAAiBA,eAAeM,OAAO,GAAGN;AAOxE,OAAO,MAAMO,qBAAqB,CAChCC,KACAC,gBACAC,KACAC,UACAC,WACAC;IAEA,MAAMC,YAAYJ,IAAIK,OAAO,CAACC,MAAM,CAACC,IAAI;IAEzC,MAAMC,UAEiF,CACrFC,WAEC,OACCC,QACA,EACEC,KAAK,EACLC,OAAO,EACP,mCAAmC;QACnCC,IAAI,EAC0E;YAEhF,MAAMC,aAAarB;YAEnB,IAAIsB;YACJ,IAAI,CAACd,UAAU;gBACbc,aAAcX,UAAUY,KAAK,EAAEC,UAC7Bb,UAAUY,KAAK,CAACE,IAAI,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAKX;gBAEzC,IAAI,CAACM,YAAY;oBACf,MAAM,IAAIM,MAAM,CAAC,KAAK,EAAEZ,SAAS,uBAAuB,EAAEX,IAAIwB,YAAY,EAAE;gBAC9E;YACF;YAEA,MAAMC,mCACJX,WAAWY,aAAaZ,WAAW,OAC/B,CAAC,IACD,OAAOA,YAAY,WACjB;gBAAEa,UAAUb;YAAQ,IACpBA;YACR,MAAMc,wCAA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