payload 4.0.0-internal.cd69eef → 4.0.0-internal.d1cc1d3

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 (279) hide show
  1. package/dist/admin/RichText.d.ts +1 -1
  2. package/dist/admin/RichText.d.ts.map +1 -1
  3. package/dist/admin/RichText.js.map +1 -1
  4. package/dist/admin/functions/index.d.ts +10 -8
  5. package/dist/admin/functions/index.d.ts.map +1 -1
  6. package/dist/admin/functions/index.js.map +1 -1
  7. package/dist/admin/types.d.ts +2 -2
  8. package/dist/admin/types.d.ts.map +1 -1
  9. package/dist/admin/types.js.map +1 -1
  10. package/dist/auth/endpoints/login.d.ts.map +1 -1
  11. package/dist/auth/endpoints/login.js +2 -11
  12. package/dist/auth/endpoints/login.js.map +1 -1
  13. package/dist/auth/loginWithCookie.d.ts +33 -0
  14. package/dist/auth/loginWithCookie.d.ts.map +1 -0
  15. package/dist/auth/loginWithCookie.js +34 -0
  16. package/dist/auth/loginWithCookie.js.map +1 -0
  17. package/dist/auth/serverFunctions/cookies.d.ts +47 -0
  18. package/dist/auth/serverFunctions/cookies.d.ts.map +1 -0
  19. package/dist/auth/serverFunctions/cookies.js +52 -0
  20. package/dist/auth/serverFunctions/cookies.js.map +1 -0
  21. package/dist/auth/serverFunctions/login.d.ts +29 -0
  22. package/dist/auth/serverFunctions/login.d.ts.map +1 -0
  23. package/dist/auth/serverFunctions/login.js +63 -0
  24. package/dist/auth/serverFunctions/login.js.map +1 -0
  25. package/dist/auth/serverFunctions/logout.d.ts +17 -0
  26. package/dist/auth/serverFunctions/logout.d.ts.map +1 -0
  27. package/dist/auth/serverFunctions/logout.js +58 -0
  28. package/dist/auth/serverFunctions/logout.js.map +1 -0
  29. package/dist/auth/serverFunctions/refresh.d.ts +17 -0
  30. package/dist/auth/serverFunctions/refresh.d.ts.map +1 -0
  31. package/dist/auth/serverFunctions/refresh.js +61 -0
  32. package/dist/auth/serverFunctions/refresh.js.map +1 -0
  33. package/dist/collections/config/client.d.ts +2 -3
  34. package/dist/collections/config/client.d.ts.map +1 -1
  35. package/dist/collections/config/client.js +5 -7
  36. package/dist/collections/config/client.js.map +1 -1
  37. package/dist/collections/config/defaults.d.ts.map +1 -1
  38. package/dist/collections/config/defaults.js +1 -0
  39. package/dist/collections/config/defaults.js.map +1 -1
  40. package/dist/collections/config/sanitize.d.ts +3 -8
  41. package/dist/collections/config/sanitize.d.ts.map +1 -1
  42. package/dist/collections/config/sanitize.js +2 -6
  43. package/dist/collections/config/sanitize.js.map +1 -1
  44. package/dist/collections/config/types.d.ts +1 -1
  45. package/dist/collections/config/types.d.ts.map +1 -1
  46. package/dist/collections/config/types.js.map +1 -1
  47. package/dist/collections/config/useAsTitle.spec.js +27 -27
  48. package/dist/collections/config/useAsTitle.spec.js.map +1 -1
  49. package/dist/collections/operations/create.d.ts.map +1 -1
  50. package/dist/collections/operations/create.js +10 -0
  51. package/dist/collections/operations/create.js.map +1 -1
  52. package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
  53. package/dist/collections/operations/restoreVersion.js +7 -4
  54. package/dist/collections/operations/restoreVersion.js.map +1 -1
  55. package/dist/collections/operations/updateByID.js +1 -0
  56. package/dist/collections/operations/updateByID.js.map +1 -1
  57. package/dist/config/build.js +1 -1
  58. package/dist/config/build.js.map +1 -1
  59. package/dist/config/defaults.d.ts.map +1 -1
  60. package/dist/config/defaults.js +5 -2
  61. package/dist/config/defaults.js.map +1 -1
  62. package/dist/config/orderable/index.d.ts +1 -1
  63. package/dist/config/orderable/index.d.ts.map +1 -1
  64. package/dist/config/orderable/index.js +2 -2
  65. package/dist/config/orderable/index.js.map +1 -1
  66. package/dist/config/sanitize.d.ts +1 -1
  67. package/dist/config/sanitize.d.ts.map +1 -1
  68. package/dist/config/sanitize.js +33 -40
  69. package/dist/config/sanitize.js.map +1 -1
  70. package/dist/config/types.d.ts +1 -1
  71. package/dist/config/types.js.map +1 -1
  72. package/dist/database/createDatabaseAdapter.d.ts +1 -1
  73. package/dist/database/createDatabaseAdapter.d.ts.map +1 -1
  74. package/dist/database/createDatabaseAdapter.js +0 -2
  75. package/dist/database/createDatabaseAdapter.js.map +1 -1
  76. package/dist/database/types.d.ts +6 -0
  77. package/dist/database/types.d.ts.map +1 -1
  78. package/dist/database/types.js.map +1 -1
  79. package/dist/exports/auth.d.ts +5 -0
  80. package/dist/exports/auth.d.ts.map +1 -0
  81. package/dist/exports/auth.js +6 -0
  82. package/dist/exports/auth.js.map +1 -0
  83. package/dist/exports/internal.d.ts +2 -0
  84. package/dist/exports/internal.d.ts.map +1 -1
  85. package/dist/exports/internal.js +3 -1
  86. package/dist/exports/internal.js.map +1 -1
  87. package/dist/fields/baseFields/slug/duplicateContext.d.ts +11 -0
  88. package/dist/fields/baseFields/slug/duplicateContext.d.ts.map +1 -0
  89. package/dist/fields/baseFields/slug/duplicateContext.js +21 -0
  90. package/dist/fields/baseFields/slug/duplicateContext.js.map +1 -0
  91. package/dist/fields/baseFields/slug/fillEmptyLocalizedSlugs.d.ts +22 -0
  92. package/dist/fields/baseFields/slug/fillEmptyLocalizedSlugs.d.ts.map +1 -0
  93. package/dist/fields/baseFields/slug/fillEmptyLocalizedSlugs.js +63 -0
  94. package/dist/fields/baseFields/slug/fillEmptyLocalizedSlugs.js.map +1 -0
  95. package/dist/fields/baseFields/slug/generateSlug.d.ts +13 -8
  96. package/dist/fields/baseFields/slug/generateSlug.d.ts.map +1 -1
  97. package/dist/fields/baseFields/slug/generateSlug.js +98 -45
  98. package/dist/fields/baseFields/slug/generateSlug.js.map +1 -1
  99. package/dist/fields/baseFields/slug/generateSlugBeforeDuplicate.d.ts +18 -0
  100. package/dist/fields/baseFields/slug/generateSlugBeforeDuplicate.d.ts.map +1 -0
  101. package/dist/fields/baseFields/slug/generateSlugBeforeDuplicate.js +20 -0
  102. package/dist/fields/baseFields/slug/generateSlugBeforeDuplicate.js.map +1 -0
  103. package/dist/fields/baseFields/slug/getSlugFallbackValue.d.ts +22 -0
  104. package/dist/fields/baseFields/slug/getSlugFallbackValue.d.ts.map +1 -0
  105. package/dist/fields/baseFields/slug/getSlugFallbackValue.js +23 -0
  106. package/dist/fields/baseFields/slug/getSlugFallbackValue.js.map +1 -0
  107. package/dist/fields/baseFields/slug/hasValue.d.ts +3 -0
  108. package/dist/fields/baseFields/slug/hasValue.d.ts.map +1 -0
  109. package/dist/fields/baseFields/slug/hasValue.js +3 -0
  110. package/dist/fields/baseFields/slug/hasValue.js.map +1 -0
  111. package/dist/fields/config/reservedFieldNames.spec.js +18 -18
  112. package/dist/fields/config/reservedFieldNames.spec.js.map +1 -1
  113. package/dist/fields/config/sanitize.d.ts +3 -9
  114. package/dist/fields/config/sanitize.d.ts.map +1 -1
  115. package/dist/fields/config/sanitize.js +33 -34
  116. package/dist/fields/config/sanitize.js.map +1 -1
  117. package/dist/fields/config/sanitize.spec.js +128 -105
  118. package/dist/fields/config/sanitize.spec.js.map +1 -1
  119. package/dist/fields/config/types.d.ts +4 -3
  120. package/dist/fields/config/types.d.ts.map +1 -1
  121. package/dist/fields/config/types.js.map +1 -1
  122. package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
  123. package/dist/fields/hooks/beforeValidate/promise.js +5 -3
  124. package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
  125. package/dist/fields/hooks/beforeValidate/stripNullRows.d.ts +10 -0
  126. package/dist/fields/hooks/beforeValidate/stripNullRows.d.ts.map +1 -0
  127. package/dist/fields/hooks/beforeValidate/stripNullRows.js +18 -0
  128. package/dist/fields/hooks/beforeValidate/stripNullRows.js.map +1 -0
  129. package/dist/fields/validations.d.ts.map +1 -1
  130. package/dist/fields/validations.js +7 -8
  131. package/dist/fields/validations.js.map +1 -1
  132. package/dist/fields/validations.spec.js +61 -37
  133. package/dist/fields/validations.spec.js.map +1 -1
  134. package/dist/globals/config/sanitize.d.ts +2 -7
  135. package/dist/globals/config/sanitize.d.ts.map +1 -1
  136. package/dist/globals/config/sanitize.js +2 -6
  137. package/dist/globals/config/sanitize.js.map +1 -1
  138. package/dist/globals/config/sanitize.spec.js +6 -6
  139. package/dist/globals/config/sanitize.spec.js.map +1 -1
  140. package/dist/globals/operations/countGlobalVersions.d.ts.map +1 -1
  141. package/dist/globals/operations/countGlobalVersions.js +1 -0
  142. package/dist/globals/operations/countGlobalVersions.js.map +1 -1
  143. package/dist/index.bundled.d.ts +247 -178
  144. package/dist/index.d.ts +49 -17
  145. package/dist/index.d.ts.map +1 -1
  146. package/dist/index.js +3 -0
  147. package/dist/index.js.map +1 -1
  148. package/dist/query-presets/constraints.js +1 -1
  149. package/dist/query-presets/constraints.js.map +1 -1
  150. package/dist/queues/config/collection.d.ts.map +1 -1
  151. package/dist/queues/config/collection.js +37 -43
  152. package/dist/queues/config/collection.js.map +1 -1
  153. package/dist/queues/config/global.d.ts +5 -6
  154. package/dist/queues/config/global.d.ts.map +1 -1
  155. package/dist/queues/config/global.js +1 -1
  156. package/dist/queues/config/global.js.map +1 -1
  157. package/dist/queues/config/types/index.d.ts +29 -24
  158. package/dist/queues/config/types/index.d.ts.map +1 -1
  159. package/dist/queues/config/types/index.js.map +1 -1
  160. package/dist/queues/config/types/taskTypes.d.ts +4 -7
  161. package/dist/queues/config/types/taskTypes.d.ts.map +1 -1
  162. package/dist/queues/config/types/taskTypes.js.map +1 -1
  163. package/dist/queues/config/types/workflowJSONTypes.d.ts +10 -9
  164. package/dist/queues/config/types/workflowJSONTypes.d.ts.map +1 -1
  165. package/dist/queues/config/types/workflowJSONTypes.js.map +1 -1
  166. package/dist/queues/config/types/workflowTypes.d.ts +11 -58
  167. package/dist/queues/config/types/workflowTypes.d.ts.map +1 -1
  168. package/dist/queues/config/types/workflowTypes.js.map +1 -1
  169. package/dist/queues/endpoints/handleSchedules.js +1 -1
  170. package/dist/queues/endpoints/handleSchedules.js.map +1 -1
  171. package/dist/queues/errors/handleTaskError.js +4 -4
  172. package/dist/queues/errors/handleTaskError.js.map +1 -1
  173. package/dist/queues/errors/handleWorkflowError.js +1 -1
  174. package/dist/queues/errors/handleWorkflowError.js.map +1 -1
  175. package/dist/queues/errors/index.d.ts +6 -0
  176. package/dist/queues/errors/index.d.ts.map +1 -1
  177. package/dist/queues/errors/index.js +5 -0
  178. package/dist/queues/errors/index.js.map +1 -1
  179. package/dist/queues/localAPI.d.ts +4 -4
  180. package/dist/queues/localAPI.d.ts.map +1 -1
  181. package/dist/queues/localAPI.js +63 -66
  182. package/dist/queues/localAPI.js.map +1 -1
  183. package/dist/queues/operations/handleSchedules/countRunnableOrActiveJobsForQueue.d.ts +4 -4
  184. package/dist/queues/operations/handleSchedules/countRunnableOrActiveJobsForQueue.d.ts.map +1 -1
  185. package/dist/queues/operations/handleSchedules/countRunnableOrActiveJobsForQueue.js.map +1 -1
  186. package/dist/queues/operations/handleSchedules/index.d.ts +1 -1
  187. package/dist/queues/operations/handleSchedules/index.d.ts.map +1 -1
  188. package/dist/queues/operations/handleSchedules/index.js +1 -1
  189. package/dist/queues/operations/handleSchedules/index.js.map +1 -1
  190. package/dist/queues/operations/runJobs/heartbeat.d.ts +13 -0
  191. package/dist/queues/operations/runJobs/heartbeat.d.ts.map +1 -0
  192. package/dist/queues/operations/runJobs/heartbeat.js +66 -0
  193. package/dist/queues/operations/runJobs/heartbeat.js.map +1 -0
  194. package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
  195. package/dist/queues/operations/runJobs/index.js +133 -84
  196. package/dist/queues/operations/runJobs/index.js.map +1 -1
  197. package/dist/queues/operations/runJobs/runJSONJob/index.d.ts.map +1 -1
  198. package/dist/queues/operations/runJobs/runJSONJob/index.js +6 -3
  199. package/dist/queues/operations/runJobs/runJSONJob/index.js.map +1 -1
  200. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +5 -5
  201. package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
  202. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.d.ts +2 -1
  203. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.d.ts.map +1 -1
  204. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js +39 -8
  205. package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js.map +1 -1
  206. package/dist/queues/operations/runJobs/runJob/importHandlerPath.js.map +1 -1
  207. package/dist/queues/operations/runJobs/runJob/index.d.ts.map +1 -1
  208. package/dist/queues/operations/runJobs/runJob/index.js +4 -4
  209. package/dist/queues/operations/runJobs/runJob/index.js.map +1 -1
  210. package/dist/queues/utilities/updateJob.d.ts.map +1 -1
  211. package/dist/queues/utilities/updateJob.js +3 -0
  212. package/dist/queues/utilities/updateJob.js.map +1 -1
  213. package/dist/types/index.d.ts +2 -2
  214. package/dist/types/index.d.ts.map +1 -1
  215. package/dist/types/index.js.map +1 -1
  216. package/dist/uploads/checkFileRestrictions.d.ts +1 -1
  217. package/dist/uploads/checkFileRestrictions.d.ts.map +1 -1
  218. package/dist/uploads/checkFileRestrictions.js +15 -1
  219. package/dist/uploads/checkFileRestrictions.js.map +1 -1
  220. package/dist/uploads/endpoints/uploadInstructions.d.ts +12 -0
  221. package/dist/uploads/endpoints/uploadInstructions.d.ts.map +1 -1
  222. package/dist/uploads/endpoints/uploadInstructions.js +66 -20
  223. package/dist/uploads/endpoints/uploadInstructions.js.map +1 -1
  224. package/dist/uploads/generateFileData.js +4 -1
  225. package/dist/uploads/generateFileData.js.map +1 -1
  226. package/dist/uploads/getFileFromUploadInstructions.d.ts +8 -0
  227. package/dist/uploads/getFileFromUploadInstructions.d.ts.map +1 -0
  228. package/dist/uploads/getFileFromUploadInstructions.js +62 -0
  229. package/dist/uploads/getFileFromUploadInstructions.js.map +1 -0
  230. package/dist/uploads/getImageSize.d.ts +12 -1
  231. package/dist/uploads/getImageSize.d.ts.map +1 -1
  232. package/dist/uploads/getImageSize.js +20 -18
  233. package/dist/uploads/getImageSize.js.map +1 -1
  234. package/dist/uploads/getImageSize.spec.js +298 -0
  235. package/dist/uploads/getImageSize.spec.js.map +1 -0
  236. package/dist/uploads/probeImageSize.d.ts +39 -0
  237. package/dist/uploads/probeImageSize.d.ts.map +1 -0
  238. package/dist/uploads/probeImageSize.js +374 -0
  239. package/dist/uploads/probeImageSize.js.map +1 -0
  240. package/dist/uploads/probeImageSize.spec.js +366 -0
  241. package/dist/uploads/probeImageSize.spec.js.map +1 -0
  242. package/dist/uploads/stagedUpload.d.ts +27 -0
  243. package/dist/uploads/stagedUpload.d.ts.map +1 -0
  244. package/dist/uploads/stagedUpload.js +197 -0
  245. package/dist/uploads/stagedUpload.js.map +1 -0
  246. package/dist/uploads/types.d.ts +41 -13
  247. package/dist/uploads/types.d.ts.map +1 -1
  248. package/dist/uploads/types.js.map +1 -1
  249. package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
  250. package/dist/utilities/addDataAndFileToRequest.js +12 -46
  251. package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
  252. package/dist/utilities/configToJSONSchema.spec.js +33 -33
  253. package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
  254. package/dist/utilities/fieldValueExists.d.ts +29 -0
  255. package/dist/utilities/fieldValueExists.d.ts.map +1 -0
  256. package/dist/utilities/fieldValueExists.js +27 -0
  257. package/dist/utilities/fieldValueExists.js.map +1 -0
  258. package/dist/utilities/getUniqueFieldValue.d.ts +27 -0
  259. package/dist/utilities/getUniqueFieldValue.d.ts.map +1 -0
  260. package/dist/utilities/getUniqueFieldValue.js +26 -0
  261. package/dist/utilities/getUniqueFieldValue.js.map +1 -0
  262. package/dist/versions/deleteScheduledPublishJobs.js +2 -2
  263. package/dist/versions/deleteScheduledPublishJobs.js.map +1 -1
  264. package/dist/versions/payloadPackageList.d.ts.map +1 -1
  265. package/dist/versions/payloadPackageList.js +0 -1
  266. package/dist/versions/payloadPackageList.js.map +1 -1
  267. package/package.json +8 -3
  268. package/dist/database/defaultUpdateJobs.d.ts +0 -3
  269. package/dist/database/defaultUpdateJobs.d.ts.map +0 -1
  270. package/dist/database/defaultUpdateJobs.js +0 -41
  271. package/dist/database/defaultUpdateJobs.js.map +0 -1
  272. package/dist/fields/baseFields/slug/countVersions.d.ts +0 -13
  273. package/dist/fields/baseFields/slug/countVersions.d.ts.map +0 -1
  274. package/dist/fields/baseFields/slug/countVersions.js +0 -27
  275. package/dist/fields/baseFields/slug/countVersions.js.map +0 -1
  276. package/dist/uploads/tempFile.d.ts +0 -7
  277. package/dist/uploads/tempFile.d.ts.map +0 -1
  278. package/dist/uploads/tempFile.js +0 -39
  279. package/dist/uploads/tempFile.js.map +0 -1
@@ -2,7 +2,7 @@ import type { Field } from '../../../fields/config/types.js';
2
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
- import type { RetryConfig, RunInlineTaskFunction, RunTaskFunctions, TaskInput, TaskOutput, TaskType } from './taskTypes.js';
5
+ import type { RetryConfig, RunInlineTaskFunction, RunTaskFunctions, TaskInput, TaskOutput, TaskSlug } from './taskTypes.js';
6
6
  import type { WorkflowJSON } from './workflowJSONTypes.js';
7
7
  export type JobLog = {
8
8
  completedAt: string;
@@ -12,7 +12,7 @@ export type JobLog = {
12
12
  * ID added by the array field when the log is saved in the database
13
13
  */
14
14
  id: string;
15
- input?: Record<string, any>;
15
+ input: Record<string, any>;
16
16
  output?: Record<string, any>;
17
17
  /**
18
18
  * Sub-tasks (tasks that are run within a task) will have a parent task ID
@@ -20,60 +20,13 @@ export type JobLog = {
20
20
  parent?: TaskParent;
21
21
  state: 'failed' | 'succeeded';
22
22
  taskID: string;
23
- taskSlug: TaskType;
23
+ taskSlug: TaskSlug;
24
24
  };
25
- /**
26
- * @deprecated - will be made private in 4.0. Please use the `Job` type instead.
27
- */
28
- export type BaseJob<TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false> = {
29
- completedAt?: null | string;
30
- /**
31
- * Used for concurrency control. Jobs with the same key are subject to exclusive/supersedes rules.
32
- */
33
- concurrencyKey?: null | string;
34
- createdAt: string;
35
- error?: unknown;
36
- hasError?: boolean;
37
- id: number | string;
38
- input: TWorkflowSlugOrInput extends false ? object : TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input'] : TWorkflowSlugOrInput;
39
- log?: JobLog[];
40
- meta?: {
41
- [key: string]: unknown;
42
- /**
43
- * If true, this job was queued by the scheduling system.
44
- */
45
- scheduled?: boolean;
46
- };
47
- processing?: boolean;
48
- queue?: string;
49
- taskSlug?: null | TaskType;
50
- taskStatus: JobTaskStatus;
51
- totalTried: number;
52
- updatedAt: string;
53
- waitUntil?: null | string;
54
- workflowSlug?: null | WorkflowTypes;
55
- };
56
- /**
57
- * @todo rename to WorkflowSlug in 4.0, similar to CollectionSlug
58
- */
59
- export type WorkflowTypes = StringKeyOf<TypedJobs['workflows']>;
60
- /**
61
- * @deprecated - will be removed in 4.0. Use `Job` type instead.
62
- */
63
- export type RunningJob<TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] | object> = {
64
- input: TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input'] : TWorkflowSlugOrInput;
65
- taskStatus: JobTaskStatus;
66
- } & Omit<TypedCollection['payload-jobs'], 'input' | 'taskStatus'>;
67
- /**
68
- * @deprecated - will be removed in 4.0. Use `Job` type instead.
69
- */
70
- export type RunningJobSimple<TWorkflowInput extends object> = {
71
- input: TWorkflowInput;
72
- } & TypedCollection['payload-jobs'];
73
- export type RunningJobFromTask<TTaskSlug extends keyof TypedJobs['tasks']> = {
25
+ export type WorkflowSlug = StringKeyOf<TypedJobs['workflows']>;
26
+ export type JobFromTask<TTaskSlug extends keyof TypedJobs['tasks']> = {
74
27
  input: TypedJobs['tasks'][TTaskSlug]['input'];
75
28
  } & TypedCollection['payload-jobs'];
76
- export type WorkflowHandler<TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false> = (args: {
29
+ export type WorkflowHandler<TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] | object = object> = (args: {
77
30
  inlineTask: RunInlineTaskFunction;
78
31
  job: Job<TWorkflowSlugOrInput>;
79
32
  req: PayloadRequest;
@@ -83,14 +36,14 @@ export type SingleTaskStatus<T extends keyof TypedJobs['tasks']> = {
83
36
  complete: boolean;
84
37
  input: TaskInput<T>;
85
38
  output: TaskOutput<T>;
86
- taskSlug: TaskType;
39
+ taskSlug: TaskSlug;
87
40
  totalTried: number;
88
41
  };
89
42
  /**
90
43
  * Task IDs mapped to their status
91
44
  */
92
45
  export type JobTaskStatus = {
93
- [taskSlug in TaskType]: {
46
+ [taskSlug in TaskSlug]: {
94
47
  [taskID: string]: SingleTaskStatus<taskSlug>;
95
48
  };
96
49
  };
@@ -125,14 +78,14 @@ export type ConcurrencyConfig<TInput = object> = ((args: {
125
78
  */
126
79
  supersedes?: boolean;
127
80
  };
128
- export type WorkflowConfig<TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false> = {
81
+ export type WorkflowConfig<TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] | object = object> = {
129
82
  /**
130
83
  * Job concurrency controls for preventing race conditions.
131
84
  *
132
85
  * Can be an object with full options, or a shorthand function that just returns the key
133
86
  * (in which case exclusive defaults to true).
134
87
  */
135
- concurrency?: ConcurrencyConfig<TWorkflowSlugOrInput extends false ? object : TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input'] : TWorkflowSlugOrInput>;
88
+ concurrency?: ConcurrencyConfig<TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input'] : TWorkflowSlugOrInput>;
136
89
  /**
137
90
  * You can either pass a string-based path to the workflow function file, or the workflow function itself.
138
91
  *
@@ -140,7 +93,7 @@ export type WorkflowConfig<TWorkflowSlugOrInput extends false | keyof TypedJobs[
140
93
  * because that will avoid bundling large dependencies in your Next.js app. Passing a string path is an advanced feature
141
94
  * that may require a sophisticated build pipeline in order to work.
142
95
  */
143
- handler: string | WorkflowHandler<TWorkflowSlugOrInput> | WorkflowJSON<TWorkflowSlugOrInput extends object ? string : TWorkflowSlugOrInput>;
96
+ handler: string | WorkflowHandler<TWorkflowSlugOrInput> | WorkflowJSON<TWorkflowSlugOrInput>;
144
97
  /**
145
98
  * Define the input field schema - payload will generate a type for this schema.
146
99
  */
@@ -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,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,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,KA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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,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1B,MAAM,C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AE,oBAAoB,SAAS,MAAM,SAAS,CAAC,WAAW,CAAC,GAAG,oBAAoB,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 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 /**\n * Used for concurrency control. Jobs with the same key are subject to exclusive/supersedes rules.\n */\n concurrencyKey?: 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\n/**\n * Concurrency configuration for workflows and tasks.\n * Controls how jobs with the same concurrency key are handled.\n */\nexport type ConcurrencyConfig<TInput = object> =\n | ((args: { input: TInput; queue: string }) => string)\n // Shorthand: key function only, exclusive defaults to true, supersedes defaults to false\n | {\n /**\n * Only one job with this key can run at a time.\n * Other jobs with the same key remain queued until the running job completes.\n * @default true\n */\n exclusive?: boolean\n /**\n * Function that returns a key to group related jobs.\n * Jobs with the same key are subject to concurrency rules.\n * The queue name is provided to allow for queue-specific concurrency keys if needed.\n */\n key: (args: { input: TInput; queue: string }) => string\n /**\n * When a new job is queued, delete older pending (not yet running) jobs with the same key.\n * Already-running jobs are not affected.\n * Useful when only the latest state matters (e.g., regenerating data after multiple rapid edits).\n * @default false\n */\n supersedes?: boolean\n }\n\nexport type WorkflowConfig<\n TWorkflowSlugOrInput extends false | keyof TypedJobs['workflows'] | object = false,\n> = {\n /**\n * Job concurrency controls for preventing race conditions.\n *\n * Can be an object with full options, or a shorthand function that just returns the key\n * (in which case exclusive defaults to true).\n */\n concurrency?: ConcurrencyConfig<\n TWorkflowSlugOrInput extends false\n ? object\n : TWorkflowSlugOrInput extends keyof TypedJobs['workflows']\n ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input']\n : TWorkflowSlugOrInput\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":"AAiKA,WA8DC"}
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 TaskSlug,\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: TaskSlug\n}\n\nexport type WorkflowSlug = StringKeyOf<TypedJobs['workflows']>\n\n// Simplified version of Job that doesn't break TypeScript (TypeScript seems to stop evaluating Job when it's too complex)\nexport type JobFromTask<TTaskSlug extends keyof TypedJobs['tasks']> = {\n input: TypedJobs['tasks'][TTaskSlug]['input']\n} & TypedCollection['payload-jobs']\n\nexport type WorkflowHandler<\n TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] | object = object,\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: TaskSlug\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 TaskSlug]: {\n [taskID: string]: SingleTaskStatus<taskSlug>\n }\n}\n\n/**\n * Concurrency configuration for workflows and tasks.\n * Controls how jobs with the same concurrency key are handled.\n */\nexport type ConcurrencyConfig<TInput = object> =\n | ((args: { input: TInput; queue: string }) => string)\n // Shorthand: key function only, exclusive defaults to true, supersedes defaults to false\n | {\n /**\n * Only one job with this key can run at a time.\n * Other jobs with the same key remain queued until the running job completes.\n * @default true\n */\n exclusive?: boolean\n /**\n * Function that returns a key to group related jobs.\n * Jobs with the same key are subject to concurrency rules.\n * The queue name is provided to allow for queue-specific concurrency keys if needed.\n */\n key: (args: { input: TInput; queue: string }) => string\n /**\n * When a new job is queued, delete older pending (not yet running) jobs with the same key.\n * Already-running jobs are not affected.\n * Useful when only the latest state matters (e.g., regenerating data after multiple rapid edits).\n * @default false\n */\n supersedes?: boolean\n }\n\nexport type WorkflowConfig<\n TWorkflowSlugOrInput extends keyof TypedJobs['workflows'] | object = object,\n> = {\n /**\n * Job concurrency controls for preventing race conditions.\n *\n * Can be an object with full options, or a shorthand function that just returns the key\n * (in which case exclusive defaults to true).\n */\n concurrency?: ConcurrencyConfig<\n TWorkflowSlugOrInput extends keyof TypedJobs['workflows']\n ? TypedJobs['workflows'][TWorkflowSlugOrInput]['input']\n : TWorkflowSlugOrInput\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: string | WorkflowHandler<TWorkflowSlugOrInput> | WorkflowJSON<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":"AAuGA,WAyDC"}
@@ -26,7 +26,7 @@ import { configHasJobs } from './run.js';
26
26
  });
27
27
  }
28
28
  if (!jobsConfig.scheduling) {
29
- // There is no reason to call the handleSchedules endpoint if the stats global is not enabled (= no schedules defined)
29
+ // There is no reason to call the handleSchedules endpoint when no schedules are defined.
30
30
  return Response.json({
31
31
  message: 'Cannot handle schedules because no tasks or workflows with schedules are defined.'
32
32
  }, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queues/endpoints/handleSchedules.ts"],"sourcesContent":["import type { Endpoint } from '../../config/types.js'\n\nimport { handleSchedules } from '../operations/handleSchedules/index.js'\nimport { configHasJobs } from './run.js'\n\n/**\n * GET /api/payload-jobs/handle-schedules endpoint\n *\n * This endpoint is GET instead of POST to allow it to be used in a Vercel Cron.\n */\nexport const handleSchedulesJobsEndpoint: Endpoint = {\n handler: async (req) => {\n const jobsConfig = req.payload.config.jobs\n\n if (!configHasJobs(jobsConfig)) {\n return Response.json(\n {\n message: 'No jobs to schedule.',\n },\n { status: 200 },\n )\n }\n\n const accessFn = jobsConfig.access?.run ?? (() => true)\n\n const hasAccess = await accessFn({ req })\n\n if (!hasAccess) {\n return Response.json(\n {\n message: req.i18n.t('error:unauthorized'),\n },\n { status: 401 },\n )\n }\n\n if (!jobsConfig.scheduling) {\n // There is no reason to call the handleSchedules endpoint if the stats global is not enabled (= no schedules defined)\n return Response.json(\n {\n message:\n 'Cannot handle schedules because no tasks or workflows with schedules are defined.',\n },\n { status: 500 },\n )\n }\n\n const { allQueues, queue } = req.query as {\n allQueues?: 'false' | 'true'\n queue?: string\n }\n\n const runAllQueues = allQueues && !(typeof allQueues === 'string' && allQueues === 'false')\n\n const { errored, queued, skipped } = await handleSchedules({\n allQueues: runAllQueues,\n queue,\n req,\n })\n\n return Response.json(\n {\n errored,\n message: req.i18n.t('general:success'),\n queued,\n skipped,\n },\n { status: 200 },\n )\n },\n method: 'get',\n path: '/handle-schedules',\n}\n"],"names":["handleSchedules","configHasJobs","handleSchedulesJobsEndpoint","handler","req","jobsConfig","payload","config","jobs","Response","json","message","status","accessFn","access","run","hasAccess","i18n","t","scheduling","allQueues","queue","query","runAllQueues","errored","queued","skipped","method","path"],"mappings":"AAEA,SAASA,eAAe,QAAQ,yCAAwC;AACxE,SAASC,aAAa,QAAQ,WAAU;AAExC;;;;CAIC,GACD,OAAO,MAAMC,8BAAwC;IACnDC,SAAS,OAAOC;QACd,MAAMC,aAAaD,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI;QAE1C,IAAI,CAACP,cAAcI,aAAa;YAC9B,OAAOI,SAASC,IAAI,CAClB;gBACEC,SAAS;YACX,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAMC,WAAWR,WAAWS,MAAM,EAAEC,OAAQ,CAAA,IAAM,IAAG;QAErD,MAAMC,YAAY,MAAMH,SAAS;YAAET;QAAI;QAEvC,IAAI,CAACY,WAAW;YACd,OAAOP,SAASC,IAAI,CAClB;gBACEC,SAASP,IAAIa,IAAI,CAACC,CAAC,CAAC;YACtB,GACA;gBAAEN,QAAQ;YAAI;QAElB;QAEA,IAAI,CAACP,WAAWc,UAAU,EAAE;YAC1B,sHAAsH;YACtH,OAAOV,SAASC,IAAI,CAClB;gBACEC,SACE;YACJ,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAM,EAAEQ,SAAS,EAAEC,KAAK,EAAE,GAAGjB,IAAIkB,KAAK;QAKtC,MAAMC,eAAeH,aAAa,CAAE,CAAA,OAAOA,cAAc,YAAYA,cAAc,OAAM;QAEzF,MAAM,EAAEI,OAAO,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAM1B,gBAAgB;YACzDoB,WAAWG;YACXF;YACAjB;QACF;QAEA,OAAOK,SAASC,IAAI,CAClB;YACEc;YACAb,SAASP,IAAIa,IAAI,CAACC,CAAC,CAAC;YACpBO;YACAC;QACF,GACA;YAAEd,QAAQ;QAAI;IAElB;IACAe,QAAQ;IACRC,MAAM;AACR,EAAC"}
1
+ {"version":3,"sources":["../../../src/queues/endpoints/handleSchedules.ts"],"sourcesContent":["import type { Endpoint } from '../../config/types.js'\n\nimport { handleSchedules } from '../operations/handleSchedules/index.js'\nimport { configHasJobs } from './run.js'\n\n/**\n * GET /api/payload-jobs/handle-schedules endpoint\n *\n * This endpoint is GET instead of POST to allow it to be used in a Vercel Cron.\n */\nexport const handleSchedulesJobsEndpoint: Endpoint = {\n handler: async (req) => {\n const jobsConfig = req.payload.config.jobs\n\n if (!configHasJobs(jobsConfig)) {\n return Response.json(\n {\n message: 'No jobs to schedule.',\n },\n { status: 200 },\n )\n }\n\n const accessFn = jobsConfig.access?.run ?? (() => true)\n\n const hasAccess = await accessFn({ req })\n\n if (!hasAccess) {\n return Response.json(\n {\n message: req.i18n.t('error:unauthorized'),\n },\n { status: 401 },\n )\n }\n\n if (!jobsConfig.scheduling) {\n // There is no reason to call the handleSchedules endpoint when no schedules are defined.\n return Response.json(\n {\n message:\n 'Cannot handle schedules because no tasks or workflows with schedules are defined.',\n },\n { status: 500 },\n )\n }\n\n const { allQueues, queue } = req.query as {\n allQueues?: 'false' | 'true'\n queue?: string\n }\n\n const runAllQueues = allQueues && !(typeof allQueues === 'string' && allQueues === 'false')\n\n const { errored, queued, skipped } = await handleSchedules({\n allQueues: runAllQueues,\n queue,\n req,\n })\n\n return Response.json(\n {\n errored,\n message: req.i18n.t('general:success'),\n queued,\n skipped,\n },\n { status: 200 },\n )\n },\n method: 'get',\n path: '/handle-schedules',\n}\n"],"names":["handleSchedules","configHasJobs","handleSchedulesJobsEndpoint","handler","req","jobsConfig","payload","config","jobs","Response","json","message","status","accessFn","access","run","hasAccess","i18n","t","scheduling","allQueues","queue","query","runAllQueues","errored","queued","skipped","method","path"],"mappings":"AAEA,SAASA,eAAe,QAAQ,yCAAwC;AACxE,SAASC,aAAa,QAAQ,WAAU;AAExC;;;;CAIC,GACD,OAAO,MAAMC,8BAAwC;IACnDC,SAAS,OAAOC;QACd,MAAMC,aAAaD,IAAIE,OAAO,CAACC,MAAM,CAACC,IAAI;QAE1C,IAAI,CAACP,cAAcI,aAAa;YAC9B,OAAOI,SAASC,IAAI,CAClB;gBACEC,SAAS;YACX,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAMC,WAAWR,WAAWS,MAAM,EAAEC,OAAQ,CAAA,IAAM,IAAG;QAErD,MAAMC,YAAY,MAAMH,SAAS;YAAET;QAAI;QAEvC,IAAI,CAACY,WAAW;YACd,OAAOP,SAASC,IAAI,CAClB;gBACEC,SAASP,IAAIa,IAAI,CAACC,CAAC,CAAC;YACtB,GACA;gBAAEN,QAAQ;YAAI;QAElB;QAEA,IAAI,CAACP,WAAWc,UAAU,EAAE;YAC1B,yFAAyF;YACzF,OAAOV,SAASC,IAAI,CAClB;gBACEC,SACE;YACJ,GACA;gBAAEC,QAAQ;YAAI;QAElB;QAEA,MAAM,EAAEQ,SAAS,EAAEC,KAAK,EAAE,GAAGjB,IAAIkB,KAAK;QAKtC,MAAMC,eAAeH,aAAa,CAAE,CAAA,OAAOA,cAAc,YAAYA,cAAc,OAAM;QAEzF,MAAM,EAAEI,OAAO,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAM1B,gBAAgB;YACzDoB,WAAWG;YACXF;YACAjB;QACF;QAEA,OAAOK,SAASC,IAAI,CAClB;YACEc;YACAb,SAASP,IAAIa,IAAI,CAACC,CAAC,CAAC;YACpBO;YACAC;QACF,GACA;YAAEd,QAAQ;QAAI;IAElB;IACAe,QAAQ;IACRC,MAAM;AACR,EAAC"}
@@ -44,9 +44,9 @@ export async function handleTaskError({ error, req, silent = false, updateJob })
44
44
  completedAt: currentDate.toISOString(),
45
45
  error: errorJSON,
46
46
  executedAt: executedAt.toISOString(),
47
- input,
47
+ input: input ?? {},
48
48
  output: output ?? {},
49
- parent: req.payload.config.jobs.addParentToTaskLog ? parent : undefined,
49
+ parent,
50
50
  state: 'failed',
51
51
  taskID,
52
52
  taskSlug
@@ -60,7 +60,7 @@ export async function handleTaskError({ error, req, silent = false, updateJob })
60
60
  log: {
61
61
  $push: taskLogToPush
62
62
  },
63
- processing: false,
63
+ processingUntil: null,
64
64
  totalTried: (job.totalTried ?? 0) + 1,
65
65
  waitUntil: job.waitUntil
66
66
  });
@@ -113,7 +113,7 @@ export async function handleTaskError({ error, req, silent = false, updateJob })
113
113
  log: {
114
114
  $push: taskLogToPush
115
115
  },
116
- processing: false,
116
+ processingUntil: null,
117
117
  totalTried: (job.totalTried ?? 0) + 1,
118
118
  waitUntil: job.waitUntil
119
119
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queues/errors/handleTaskError.ts"],"sourcesContent":["import ObjectIdImport from 'bson-objectid'\n\nimport type { JobLog, PayloadRequest } from '../../index.js'\nimport type { RunJobsSilent } from '../localAPI.js'\nimport type { UpdateJobFunction } from '../operations/runJobs/runJob/getUpdateJobFunction.js'\nimport type { TaskError } from './index.js'\n\nimport { getCurrentDate } from '../utilities/getCurrentDate.js'\nimport { calculateBackoffWaitUntil } from './calculateBackoffWaitUntil.js'\nimport { getWorkflowRetryBehavior } from './getWorkflowRetryBehavior.js'\n\nconst ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport\n\nexport async function handleTaskError({\n error,\n req,\n silent = false,\n updateJob,\n}: {\n error: TaskError\n req: PayloadRequest\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n updateJob: UpdateJobFunction\n}): Promise<{\n hasFinalError: boolean\n}> {\n const {\n executedAt,\n input,\n job,\n output,\n parent,\n retriesConfig,\n taskConfig,\n taskID,\n taskSlug,\n taskStatus,\n workflowConfig,\n } = error.args\n\n if (taskConfig?.onFail) {\n await taskConfig.onFail({\n input,\n job,\n req,\n taskStatus,\n })\n }\n\n const errorJSON = {\n name: error.name,\n cancelled: Boolean('cancelled' in error && error.cancelled),\n message: error.message,\n stack: error.stack,\n }\n\n const currentDate = getCurrentDate()\n\n if (job.waitUntil) {\n // Check if waitUntil is in the past\n const waitUntil = new Date(job.waitUntil)\n if (waitUntil < currentDate) {\n // Outdated waitUntil, remove it\n delete job.waitUntil\n }\n }\n\n let maxRetries: number = 0\n\n if (retriesConfig?.attempts === undefined || retriesConfig?.attempts === null) {\n // Inherit retries from workflow config, if they are undefined and the workflow config has retries configured\n if (workflowConfig.retries !== undefined && workflowConfig.retries !== null) {\n maxRetries =\n typeof workflowConfig.retries === 'object'\n ? typeof workflowConfig.retries.attempts === 'number'\n ? workflowConfig.retries.attempts\n : 0\n : workflowConfig.retries\n } else {\n maxRetries = 0\n }\n } else {\n maxRetries = retriesConfig.attempts\n }\n\n const taskLogToPush: JobLog = {\n id: new ObjectId().toHexString(),\n completedAt: currentDate.toISOString(),\n error: errorJSON,\n executedAt: executedAt.toISOString(),\n input,\n output: output ?? {},\n parent: req.payload.config.jobs.addParentToTaskLog ? parent : undefined,\n state: 'failed',\n taskID,\n taskSlug,\n }\n\n if (!taskStatus?.complete && (taskStatus?.totalTried ?? 0) >= maxRetries) {\n /**\n * Task reached max retries => workflow will not retry\n */\n\n await updateJob({\n error: errorJSON,\n hasError: true,\n log: {\n $push: taskLogToPush,\n } as any,\n processing: false,\n totalTried: (job.totalTried ?? 0) + 1,\n waitUntil: job.waitUntil,\n })\n\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n req.payload.logger.error({\n err: error,\n job,\n msg: `Error running task ${taskID}. Attempt ${job.totalTried} - max retries reached`,\n taskSlug,\n })\n }\n return {\n hasFinalError: true,\n }\n }\n\n /**\n * Task can retry:\n * - If workflow can retry, allow it to retry\n * - If workflow reached max retries, do not retry and set final error\n */\n\n // First set task waitUntil - if the workflow waitUntil is later, it will be updated later\n const taskWaitUntil: Date = calculateBackoffWaitUntil({\n retriesConfig,\n totalTried: taskStatus?.totalTried ?? 0,\n })\n\n // Update job's waitUntil only if this waitUntil is later than the current one\n if (!job.waitUntil || taskWaitUntil > new Date(job.waitUntil)) {\n job.waitUntil = taskWaitUntil.toISOString()\n }\n\n const { hasFinalError, maxWorkflowRetries, waitUntil } = getWorkflowRetryBehavior({\n job,\n retriesConfig: workflowConfig.retries,\n })\n\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n req.payload.logger.error({\n err: error,\n job,\n msg: `Error running task ${taskID}. Attempt ${job.totalTried + 1}${maxWorkflowRetries !== undefined ? '/' + (maxWorkflowRetries + 1) : ''}`,\n taskSlug,\n })\n }\n\n // Update job's waitUntil only if this waitUntil is later than the current one\n if (waitUntil && (!job.waitUntil || waitUntil > new Date(job.waitUntil))) {\n job.waitUntil = waitUntil.toISOString()\n }\n\n // Tasks update the job if they error - but in case there is an unhandled error (e.g. in the workflow itself, not in a task)\n // we need to ensure the job is updated to reflect the error\n await updateJob({\n error: hasFinalError ? errorJSON : undefined,\n hasError: hasFinalError, // If reached max retries => final error. If hasError is true this job will not be retried\n log: {\n $push: taskLogToPush,\n } as any,\n processing: false,\n totalTried: (job.totalTried ?? 0) + 1,\n waitUntil: job.waitUntil,\n })\n\n return {\n hasFinalError,\n }\n}\n"],"names":["ObjectIdImport","getCurrentDate","calculateBackoffWaitUntil","getWorkflowRetryBehavior","ObjectId","default","handleTaskError","error","req","silent","updateJob","executedAt","input","job","output","parent","retriesConfig","taskConfig","taskID","taskSlug","taskStatus","workflowConfig","args","onFail","errorJSON","name","cancelled","Boolean","message","stack","currentDate","waitUntil","Date","maxRetries","attempts","undefined","retries","taskLogToPush","id","toHexString","completedAt","toISOString","payload","config","jobs","addParentToTaskLog","state","complete","totalTried","hasError","log","$push","processing","logger","err","msg","hasFinalError","taskWaitUntil","maxWorkflowRetries"],"mappings":"AAAA,OAAOA,oBAAoB,gBAAe;AAO1C,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,MAAMC,WAAW,aAAaJ,iBAAiBA,eAAeK,OAAO,GAAGL;AAExE,OAAO,eAAeM,gBAAgB,EACpCC,KAAK,EACLC,GAAG,EACHC,SAAS,KAAK,EACdC,SAAS,EAcV;IAGC,MAAM,EACJC,UAAU,EACVC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,MAAM,EACNC,aAAa,EACbC,UAAU,EACVC,MAAM,EACNC,QAAQ,EACRC,UAAU,EACVC,cAAc,EACf,GAAGd,MAAMe,IAAI;IAEd,IAAIL,YAAYM,QAAQ;QACtB,MAAMN,WAAWM,MAAM,CAAC;YACtBX;YACAC;YACAL;YACAY;QACF;IACF;IAEA,MAAMI,YAAY;QAChBC,MAAMlB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AAU;QACdH,OAAOiD,gBAAgBhC,YAAYW;QACnCc,UAAUO;QACVN,KAAK;YACHC,OAAOd;QACT;QACAe,YAAY;QACZJ,YAAY,AAACnC,CAAAA,IAAImC,UAAU,IAAI,CAAA,IAAK;QACpCjB,WAAWlB,IAAIkB,SAAS;IAC1B;IAEA,OAAO;QACLyB;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/queues/errors/handleTaskError.ts"],"sourcesContent":["import ObjectIdImport from 'bson-objectid'\n\nimport type { JobLog, PayloadRequest } from '../../index.js'\nimport type { RunJobsSilent } from '../localAPI.js'\nimport type { UpdateJobFunction } from '../operations/runJobs/runJob/getUpdateJobFunction.js'\nimport type { TaskError } from './index.js'\n\nimport { getCurrentDate } from '../utilities/getCurrentDate.js'\nimport { calculateBackoffWaitUntil } from './calculateBackoffWaitUntil.js'\nimport { getWorkflowRetryBehavior } from './getWorkflowRetryBehavior.js'\n\nconst ObjectId = 'default' in ObjectIdImport ? ObjectIdImport.default : ObjectIdImport\n\nexport async function handleTaskError({\n error,\n req,\n silent = false,\n updateJob,\n}: {\n error: TaskError\n req: PayloadRequest\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n updateJob: UpdateJobFunction\n}): Promise<{\n hasFinalError: boolean\n}> {\n const {\n executedAt,\n input,\n job,\n output,\n parent,\n retriesConfig,\n taskConfig,\n taskID,\n taskSlug,\n taskStatus,\n workflowConfig,\n } = error.args\n\n if (taskConfig?.onFail) {\n await taskConfig.onFail({\n input,\n job,\n req,\n taskStatus,\n })\n }\n\n const errorJSON = {\n name: error.name,\n cancelled: Boolean('cancelled' in error && error.cancelled),\n message: error.message,\n stack: error.stack,\n }\n\n const currentDate = getCurrentDate()\n\n if (job.waitUntil) {\n // Check if waitUntil is in the past\n const waitUntil = new Date(job.waitUntil)\n if (waitUntil < currentDate) {\n // Outdated waitUntil, remove it\n delete job.waitUntil\n }\n }\n\n let maxRetries: number = 0\n\n if (retriesConfig?.attempts === undefined || retriesConfig?.attempts === null) {\n // Inherit retries from workflow config, if they are undefined and the workflow config has retries configured\n if (workflowConfig.retries !== undefined && workflowConfig.retries !== null) {\n maxRetries =\n typeof workflowConfig.retries === 'object'\n ? typeof workflowConfig.retries.attempts === 'number'\n ? workflowConfig.retries.attempts\n : 0\n : workflowConfig.retries\n } else {\n maxRetries = 0\n }\n } else {\n maxRetries = retriesConfig.attempts\n }\n\n const taskLogToPush: JobLog = {\n id: new ObjectId().toHexString(),\n completedAt: currentDate.toISOString(),\n error: errorJSON,\n executedAt: executedAt.toISOString(),\n input: input ?? {},\n output: output ?? {},\n parent,\n state: 'failed',\n taskID,\n taskSlug,\n }\n\n if (!taskStatus?.complete && (taskStatus?.totalTried ?? 0) >= maxRetries) {\n /**\n * Task reached max retries => workflow will not retry\n */\n\n await updateJob({\n error: errorJSON,\n hasError: true,\n log: {\n $push: taskLogToPush,\n } as any,\n processingUntil: null,\n totalTried: (job.totalTried ?? 0) + 1,\n waitUntil: job.waitUntil,\n })\n\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n req.payload.logger.error({\n err: error,\n job,\n msg: `Error running task ${taskID}. Attempt ${job.totalTried} - max retries reached`,\n taskSlug,\n })\n }\n return {\n hasFinalError: true,\n }\n }\n\n /**\n * Task can retry:\n * - If workflow can retry, allow it to retry\n * - If workflow reached max retries, do not retry and set final error\n */\n\n // First set task waitUntil - if the workflow waitUntil is later, it will be updated later\n const taskWaitUntil: Date = calculateBackoffWaitUntil({\n retriesConfig,\n totalTried: taskStatus?.totalTried ?? 0,\n })\n\n // Update job's waitUntil only if this waitUntil is later than the current one\n if (!job.waitUntil || taskWaitUntil > new Date(job.waitUntil)) {\n job.waitUntil = taskWaitUntil.toISOString()\n }\n\n const { hasFinalError, maxWorkflowRetries, waitUntil } = getWorkflowRetryBehavior({\n job,\n retriesConfig: workflowConfig.retries,\n })\n\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n req.payload.logger.error({\n err: error,\n job,\n msg: `Error running task ${taskID}. Attempt ${job.totalTried + 1}${maxWorkflowRetries !== undefined ? '/' + (maxWorkflowRetries + 1) : ''}`,\n taskSlug,\n })\n }\n\n // Update job's waitUntil only if this waitUntil is later than the current one\n if (waitUntil && (!job.waitUntil || waitUntil > new Date(job.waitUntil))) {\n job.waitUntil = waitUntil.toISOString()\n }\n\n // Tasks update the job if they error - but in case there is an unhandled error (e.g. in the workflow itself, not in a task)\n // we need to ensure the job is updated to reflect the error\n await updateJob({\n error: hasFinalError ? errorJSON : undefined,\n hasError: hasFinalError, // If reached max retries => final error. If hasError is true this job will not be retried\n log: {\n $push: taskLogToPush,\n } as any,\n processingUntil: null,\n totalTried: (job.totalTried ?? 0) + 1,\n waitUntil: job.waitUntil,\n })\n\n return {\n hasFinalError,\n }\n}\n"],"names":["ObjectIdImport","getCurrentDate","calculateBackoffWaitUntil","getWorkflowRetryBehavior","ObjectId","default","handleTaskError","error","req","silent","updateJob","executedAt","input","job","output","parent","retriesConfig","taskConfig","taskID","taskSlug","taskStatus","workflowConfig","args","onFail","errorJSON","name","cancelled","Boolean","message","stack","currentDate","waitUntil","Date","maxRetries","attempts","undefined","retries","taskLogToPush","id","toHexString","completedAt","toISOString","state","complete","totalTried","hasError","log","$push","processingUntil","payload","logger","err","msg","hasFinalError","taskWaitUntil","maxWorkflowRetries"],"mappings":"AAAA,OAAOA,oBAAoB,gBAAe;AAO1C,SAASC,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,yBAAyB,QAAQ,iCAAgC;AAC1E,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE,MAAMC,WAAW,aAAaJ,iBAAiBA,eAAeK,OAAO,GAAGL;AAExE,OAAO,eAAeM,gBAAgB,EACpCC,KAAK,EACLC,GAAG,EACHC,SAAS,KAAK,EACdC,SAAS,EAcV;IAGC,MAAM,EACJC,UAAU,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;QACF;IACF;IAEA,8EAA8E;IAC9E,IAAIY,aAAc,CAAA,CAAClB,IAAIkB,SAAS,IAAIA,YAAY,IAAIC,KAAKnB,IAAIkB,SAAS,CAAA,GAAI;QACxElB,IAAIkB,SAAS,GAAGA,UAAUU,WAAW;IACvC;IAEA,4HAA4H;IAC5H,4DAA4D;IAC5D,MAAM/B,UAAU;QACdH,OAAO8C,gBAAgB7B,YAAYW;QACnCU,UAAUQ;QACVP,KAAK;YACHC,OAAOV;QACT;QACAW,iBAAiB;QACjBJ,YAAY,AAAC/B,CAAAA,IAAI+B,UAAU,IAAI,CAAA,IAAK;QACpCb,WAAWlB,IAAIkB,SAAS;IAC1B;IAEA,OAAO;QACLsB;IACF;AACF"}
@@ -53,7 +53,7 @@ import { getWorkflowRetryBehavior } from './getWorkflowRetryBehavior.js';
53
53
  await updateJob({
54
54
  error: errorJSON,
55
55
  hasError: hasFinalError,
56
- processing: false,
56
+ processingUntil: null,
57
57
  totalTried: (job.totalTried ?? 0) + 1,
58
58
  waitUntil: job.waitUntil
59
59
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/queues/errors/handleWorkflowError.ts"],"sourcesContent":["import type { PayloadRequest } from '../../index.js'\nimport type { RunJobsSilent } from '../localAPI.js'\nimport type { UpdateJobFunction } from '../operations/runJobs/runJob/getUpdateJobFunction.js'\nimport type { WorkflowError } from './index.js'\n\nimport { getCurrentDate } from '../utilities/getCurrentDate.js'\nimport { getWorkflowRetryBehavior } from './getWorkflowRetryBehavior.js'\n\n/**\n * This is called if a workflow catches an error. It determines if it's a final error\n * or not and handles logging.\n * A Workflow error = error that happens anywhere in between running tasks.\n *\n * This function assumes that the error is not a TaskError, but a WorkflowError. If a task errors,\n * only a TaskError should be thrown, not a WorkflowError.\n */\nexport async function handleWorkflowError({\n error,\n req,\n silent = false,\n updateJob,\n}: {\n error: WorkflowError\n req: PayloadRequest\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n updateJob: UpdateJobFunction\n}): Promise<{\n hasFinalError: boolean\n}> {\n const { job, workflowConfig } = error.args\n\n const errorJSON = {\n name: error.name,\n cancelled: Boolean('cancelled' in error && error.cancelled),\n message: error.message,\n stack: error.stack,\n }\n\n // No retries configured => permanently fail. Errors reaching this handler are\n // workflow-level (task errors are routed to handleTaskError first), so there's\n // nothing else to bound them.\n const hasNoRetriesConfigured =\n workflowConfig.retries === undefined || workflowConfig.retries === null\n\n const { hasFinalError, maxWorkflowRetries, waitUntil } = hasNoRetriesConfigured\n ? { hasFinalError: true, maxWorkflowRetries: undefined, waitUntil: undefined }\n : getWorkflowRetryBehavior({\n job,\n retriesConfig: workflowConfig.retries,\n })\n\n if (!hasFinalError) {\n if (job.waitUntil) {\n // Check if waitUntil is in the past\n const waitUntil = new Date(job.waitUntil)\n if (waitUntil < getCurrentDate()) {\n // Outdated waitUntil, remove it\n delete job.waitUntil\n }\n }\n\n // Update job's waitUntil only if this waitUntil is later than the current one\n if (waitUntil && (!job.waitUntil || waitUntil > new Date(job.waitUntil))) {\n job.waitUntil = waitUntil.toISOString()\n }\n }\n\n const jobLabel = job.workflowSlug || `Task: ${job.taskSlug}`\n\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n req.payload.logger.error({\n err: error,\n msg: `Error running job ${jobLabel} id: ${job.id} attempt ${job.totalTried + 1}${maxWorkflowRetries !== undefined ? '/' + (maxWorkflowRetries + 1) : ''}`,\n })\n }\n\n // Tasks update the job if they error - but in case there is an unhandled error (e.g. in the workflow itself, not in a task)\n // we need to ensure the job is updated to reflect the error\n await updateJob({\n error: errorJSON,\n hasError: hasFinalError, // If reached max retries => final error. If hasError is true this job will not be retried\n processing: false,\n totalTried: (job.totalTried ?? 0) + 1,\n waitUntil: job.waitUntil,\n })\n\n return {\n hasFinalError,\n }\n}\n"],"names":["getCurrentDate","getWorkflowRetryBehavior","handleWorkflowError","error","req","silent","updateJob","job","workflowConfig","args","errorJSON","name","cancelled","Boolean","message","stack","hasNoRetriesConfigured","retries","undefined","hasFinalError","maxWorkflowRetries","waitUntil","retriesConfig","Date","toISOString","jobLabel","workflowSlug","taskSlug","payload","logger","err","msg","id","totalTried","hasError","processing"],"mappings":"AAKA,SAASA,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE;;;;;;;CAOC,GACD,OAAO,eAAeC,oBAAoB,EACxCC,KAAK,EACLC,GAAG,EACHC,SAAS,KAAK,EACdC,SAAS,EAcV;IAGC,MAAM,EAAEC,GAAG,EAAEC,cAAc,EAAE,GAAGL,MAAMM,IAAI;IAE1C,MAAMC,YAAY;QAChBC,MAAMR,MAAMQ,IAAI;QAChBC,WAAWC,QAAQ,eAAeV,SAASA,MAAMS,SAAS;QAC1DE,SAASX,MAAMW,OAAO;QACtBC,OAAOZ,MAAMY,KAAK;IACpB;IAEA,8EAA8E;IAC9E,+EAA+E;IAC/E,8BAA8B;IAC9B,MAAMC,yBACJR,eAAeS,OAAO,KAAKC,aAAaV,eAAeS,OAAO,KAAK;IAErE,MAAM,EAAEE,aAAa,EAAEC,kBAAkB,EAAEC,SAAS,EAAE,GAAGL,yBACrD;QAAEG,eAAe;QAAMC,oBAAoBF;QAAWG,WAAWH;IAAU,IAC3EjB,yBAAyB;QACvBM;QACAe,eAAed,eAAeS,OAAO;IACvC;IAEJ,IAAI,CAACE,eAAe;QAClB,IAAIZ,IAAIc,SAAS,EAAE;YACjB,oCAAoC;YACpC,MAAMA,YAAY,IAAIE,KAAKhB,IAAIc,SAAS;YACxC,IAAIA,YAAYrB,kBAAkB;gBAChC,gCAAgC;gBAChC,OAAOO,IAAIc,SAAS;YACtB;QACF;QAEA,8EAA8E;QAC9E,IAAIA,aAAc,CAAA,CAACd,IAAIc,SAAS,IAAIA,YAAY,IAAIE,KAAKhB,IAAIc,SAAS,CAAA,GAAI;YACxEd,IAAIc,SAAS,GAAGA,UAAUG,WAAW;QACvC;IACF;IAEA,MAAMC,WAAWlB,IAAImB,YAAY,IAAI,CAAC,MAAM,EAAEnB,IAAIoB,QAAQ,EAAE;IAE5D,IAAI,CAACtB,UAAW,OAAOA,WAAW,YAAY,CAACA,OAAOF,KAAK,EAAG;QAC5DC,IAAIwB,OAAO,CAACC,MAAM,CAAC1B,KAAK,CAAC;YACvB2B,KAAK3B;YACL4B,KAAK,CAAC,kBAAkB,EAAEN,SAAS,KAAK,EAAElB,IAAIyB,EAAE,CAAC,SAAS,EAAEzB,IAAI0B,UAAU,GAAG,IAAIb,uBAAuBF,YAAY,MAAOE,CAAAA,qBAAqB,CAAA,IAAK,IAAI;QAC3J;IACF;IAEA,4HAA4H;IAC5H,4DAA4D;IAC5D,MAAMd,UAAU;QACdH,OAAOO;QACPwB,UAAUf;QACVgB,YAAY;QACZF,YAAY,AAAC1B,CAAAA,IAAI0B,UAAU,IAAI,CAAA,IAAK;QACpCZ,WAAWd,IAAIc,SAAS;IAC1B;IAEA,OAAO;QACLF;IACF;AACF"}
1
+ {"version":3,"sources":["../../../src/queues/errors/handleWorkflowError.ts"],"sourcesContent":["import type { PayloadRequest } from '../../index.js'\nimport type { RunJobsSilent } from '../localAPI.js'\nimport type { UpdateJobFunction } from '../operations/runJobs/runJob/getUpdateJobFunction.js'\nimport type { WorkflowError } from './index.js'\n\nimport { getCurrentDate } from '../utilities/getCurrentDate.js'\nimport { getWorkflowRetryBehavior } from './getWorkflowRetryBehavior.js'\n\n/**\n * This is called if a workflow catches an error. It determines if it's a final error\n * or not and handles logging.\n * A Workflow error = error that happens anywhere in between running tasks.\n *\n * This function assumes that the error is not a TaskError, but a WorkflowError. If a task errors,\n * only a TaskError should be thrown, not a WorkflowError.\n */\nexport async function handleWorkflowError({\n error,\n req,\n silent = false,\n updateJob,\n}: {\n error: WorkflowError\n req: PayloadRequest\n /**\n * If set to true, the job system will not log any output to the console (for both info and error logs).\n * Can be an option for more granular control over logging.\n *\n * This will not automatically affect user-configured logs (e.g. if you call `console.log` or `payload.logger.info` in your job code).\n *\n * @default false\n */\n silent?: RunJobsSilent\n updateJob: UpdateJobFunction\n}): Promise<{\n hasFinalError: boolean\n}> {\n const { job, workflowConfig } = error.args\n\n const errorJSON = {\n name: error.name,\n cancelled: Boolean('cancelled' in error && error.cancelled),\n message: error.message,\n stack: error.stack,\n }\n\n // No retries configured => permanently fail. Errors reaching this handler are\n // workflow-level (task errors are routed to handleTaskError first), so there's\n // nothing else to bound them.\n const hasNoRetriesConfigured =\n workflowConfig.retries === undefined || workflowConfig.retries === null\n\n const { hasFinalError, maxWorkflowRetries, waitUntil } = hasNoRetriesConfigured\n ? { hasFinalError: true, maxWorkflowRetries: undefined, waitUntil: undefined }\n : getWorkflowRetryBehavior({\n job,\n retriesConfig: workflowConfig.retries,\n })\n\n if (!hasFinalError) {\n if (job.waitUntil) {\n // Check if waitUntil is in the past\n const waitUntil = new Date(job.waitUntil)\n if (waitUntil < getCurrentDate()) {\n // Outdated waitUntil, remove it\n delete job.waitUntil\n }\n }\n\n // Update job's waitUntil only if this waitUntil is later than the current one\n if (waitUntil && (!job.waitUntil || waitUntil > new Date(job.waitUntil))) {\n job.waitUntil = waitUntil.toISOString()\n }\n }\n\n const jobLabel = job.workflowSlug || `Task: ${job.taskSlug}`\n\n if (!silent || (typeof silent === 'object' && !silent.error)) {\n req.payload.logger.error({\n err: error,\n msg: `Error running job ${jobLabel} id: ${job.id} attempt ${job.totalTried + 1}${maxWorkflowRetries !== undefined ? '/' + (maxWorkflowRetries + 1) : ''}`,\n })\n }\n\n // Tasks update the job if they error - but in case there is an unhandled error (e.g. in the workflow itself, not in a task)\n // we need to ensure the job is updated to reflect the error\n await updateJob({\n error: errorJSON,\n hasError: hasFinalError, // If reached max retries => final error. If hasError is true this job will not be retried\n processingUntil: null,\n totalTried: (job.totalTried ?? 0) + 1,\n waitUntil: job.waitUntil,\n })\n\n return {\n hasFinalError,\n }\n}\n"],"names":["getCurrentDate","getWorkflowRetryBehavior","handleWorkflowError","error","req","silent","updateJob","job","workflowConfig","args","errorJSON","name","cancelled","Boolean","message","stack","hasNoRetriesConfigured","retries","undefined","hasFinalError","maxWorkflowRetries","waitUntil","retriesConfig","Date","toISOString","jobLabel","workflowSlug","taskSlug","payload","logger","err","msg","id","totalTried","hasError","processingUntil"],"mappings":"AAKA,SAASA,cAAc,QAAQ,iCAAgC;AAC/D,SAASC,wBAAwB,QAAQ,gCAA+B;AAExE;;;;;;;CAOC,GACD,OAAO,eAAeC,oBAAoB,EACxCC,KAAK,EACLC,GAAG,EACHC,SAAS,KAAK,EACdC,SAAS,EAcV;IAGC,MAAM,EAAEC,GAAG,EAAEC,cAAc,EAAE,GAAGL,MAAMM,IAAI;IAE1C,MAAMC,YAAY;QAChBC,MAAMR,MAAMQ,IAAI;QAChBC,WAAWC,QAAQ,eAAeV,SAASA,MAAMS,SAAS;QAC1DE,SAASX,MAAMW,OAAO;QACtBC,OAAOZ,MAAMY,KAAK;IACpB;IAEA,8EAA8E;IAC9E,+EAA+E;IAC/E,8BAA8B;IAC9B,MAAMC,yBACJR,eAAeS,OAAO,KAAKC,aAAaV,eAAeS,OAAO,KAAK;IAErE,MAAM,EAAEE,aAAa,EAAEC,kBAAkB,EAAEC,SAAS,EAAE,GAAGL,yBACrD;QAAEG,eAAe;QAAMC,oBAAoBF;QAAWG,WAAWH;IAAU,IAC3EjB,yBAAyB;QACvBM;QACAe,eAAed,eAAeS,OAAO;IACvC;IAEJ,IAAI,CAACE,eAAe;QAClB,IAAIZ,IAAIc,SAAS,EAAE;YACjB,oCAAoC;YACpC,MAAMA,YAAY,IAAIE,KAAKhB,IAAIc,SAAS;YACxC,IAAIA,YAAYrB,kBAAkB;gBAChC,gCAAgC;gBAChC,OAAOO,IAAIc,SAAS;YACtB;QACF;QAEA,8EAA8E;QAC9E,IAAIA,aAAc,CAAA,CAACd,IAAIc,SAAS,IAAIA,YAAY,IAAIE,KAAKhB,IAAIc,SAAS,CAAA,GAAI;YACxEd,IAAIc,SAAS,GAAGA,UAAUG,WAAW;QACvC;IACF;IAEA,MAAMC,WAAWlB,IAAImB,YAAY,IAAI,CAAC,MAAM,EAAEnB,IAAIoB,QAAQ,EAAE;IAE5D,IAAI,CAACtB,UAAW,OAAOA,WAAW,YAAY,CAACA,OAAOF,KAAK,EAAG;QAC5DC,IAAIwB,OAAO,CAACC,MAAM,CAAC1B,KAAK,CAAC;YACvB2B,KAAK3B;YACL4B,KAAK,CAAC,kBAAkB,EAAEN,SAAS,KAAK,EAAElB,IAAIyB,EAAE,CAAC,SAAS,EAAEzB,IAAI0B,UAAU,GAAG,IAAIb,uBAAuBF,YAAY,MAAOE,CAAAA,qBAAqB,CAAA,IAAK,IAAI;QAC3J;IACF;IAEA,4HAA4H;IAC5H,4DAA4D;IAC5D,MAAMd,UAAU;QACdH,OAAOO;QACPwB,UAAUf;QACVgB,iBAAiB;QACjBF,YAAY,AAAC1B,CAAAA,IAAI0B,UAAU,IAAI,CAAA,IAAK;QACpCZ,WAAWd,IAAIc,SAAS;IAC1B;IAEA,OAAO;QACLF;IACF;AACF"}
@@ -28,6 +28,12 @@ export declare class WorkflowError extends Error {
28
28
  args: WorkflowErrorArgs;
29
29
  constructor(args: WorkflowErrorArgs);
30
30
  }
31
+ /**
32
+ * Stops the current job run after this worker loses ownership.
33
+ * The job remains recoverable by another worker.
34
+ */
35
+ export declare class JobRunAbortedError extends Error {
36
+ }
31
37
  /**
32
38
  * Throw this error from within a task or workflow handler to cancel the job.
33
39
  * Unlike failing a job (e.g. by throwing any other error), a cancelled job will not be retried.
@@ -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,MAA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O,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,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;IACnB,YAAY,IAAI,EAAE,aAAa,EAG9B;CACF;AACD,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,EAAE,iBAAiB,CAAA;IAEvB,YAAY,IAAI,EAAE,iBAAiB,EAGlC;CACF;AAED;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;CAAG;AAEhD;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAO,EAAE,MAAM,EAE1B;CACF"}
@@ -12,6 +12,11 @@ export class WorkflowError extends Error {
12
12
  this.args = args;
13
13
  }
14
14
  }
15
+ /**
16
+ * Stops the current job run after this worker loses ownership.
17
+ * The job remains recoverable by another worker.
18
+ */ export class JobRunAbortedError extends Error {
19
+ }
15
20
  /**
16
21
  * Throw this error from within a task or workflow handler to cancel the job.
17
22
  * Unlike failing a job (e.g. by throwing any other error), a cancelled job will not be retried.
@@ -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\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"}
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 * Stops the current job run after this worker loses ownership.\n * The job remains recoverable by another worker.\n */\nexport class JobRunAbortedError extends Error {}\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","JobRunAbortedError","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,2BAA2BJ;AAAO;AAE/C;;;CAGC,GACD,OAAO,MAAMK,0BAA0BL;IACrC,YAAYE,OAAe,CAAE;QAC3B,KAAK,CAACA;IACR;AACF"}
@@ -1,4 +1,4 @@
1
- import type { BaseJob, RunningJobFromTask } from './config/types/workflowTypes.js';
1
+ import type { JobFromTask } from './config/types/workflowTypes.js';
2
2
  import { type Job, type Payload, type PayloadRequest, type Sort, type TypedJobs, type Where } from '../index.js';
3
3
  import { type HandleSchedulesResult } from './operations/handleSchedules/index.js';
4
4
  import { runJobs } from './operations/runJobs/index.js';
@@ -25,7 +25,7 @@ export declare const getJobsLocalAPI: (payload: Payload) => {
25
25
  }) => Promise<HandleSchedulesResult>;
26
26
  queue: <TTaskOrWorkflowSlug extends keyof TypedJobs['tasks'] | keyof TypedJobs['workflows']>(args: {
27
27
  input: TypedJobs['tasks'][TTaskOrWorkflowSlug]['input'];
28
- meta?: BaseJob['meta'];
28
+ meta?: Job['meta'];
29
29
  /**
30
30
  * If set to false, access control as defined in jobsConfig.access.queue will be run.
31
31
  * By default, this is true and no access control will be run.
@@ -48,7 +48,7 @@ export declare const getJobsLocalAPI: (payload: Payload) => {
48
48
  workflow?: never;
49
49
  } | {
50
50
  input: TypedJobs['workflows'][TTaskOrWorkflowSlug]['input'];
51
- meta?: BaseJob['meta'];
51
+ meta?: Job['meta'];
52
52
  /**
53
53
  * If set to false, access control as defined in jobsConfig.access.queue will be run.
54
54
  * By default, this is true and no access control will be run.
@@ -69,7 +69,7 @@ export declare const getJobsLocalAPI: (payload: Payload) => {
69
69
  task?: never;
70
70
  waitUntil?: Date;
71
71
  workflow: TTaskOrWorkflowSlug extends keyof TypedJobs['workflows'] ? TTaskOrWorkflowSlug : never;
72
- }) => Promise<TTaskOrWorkflowSlug extends keyof TypedJobs['workflows'] ? Job<TTaskOrWorkflowSlug> : RunningJobFromTask<TTaskOrWorkflowSlug>>;
72
+ }) => Promise<TTaskOrWorkflowSlug extends keyof TypedJobs['workflows'] ? Job<TTaskOrWorkflowSlug> : JobFromTask<TTaskOrWorkflowSlug>>;
73
73
  run: (args?: {
74
74
  /**
75
75
  * If you want to run jobs from all queues, set this to true.
@@ -1 +1 @@
1
- {"version":3,"file":"localAPI.d.ts","sourceRoot":"","sources":["../../src/queues/localAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AAElF,OAAO,EAGL,KAAK,GAAG,EACR,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,KAAK,EACX,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAmB,KAAK,qBAAqB,EAAE,MAAM,uCAAuC,CAAA;AACnG,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAA;AAGvD,MAAM,MAAM,aAAa,GACrB;IACE,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,GACD,OAAO,CAAA;AACX,eAAO,MAAM,eAAe,YAAa,OAAO;IAC9C,eAAe,UAAgB;QAC7B;;;;;WAKG;QACH,SAAS,CAAC,EAAE,OAAO,CAAA;QAInB;;;;WAIG;QACH,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,GAAG,CAAC,EAAE,cAAc,CAAA;KACrB,KAAG,OAAO,CAAC,qBAAqB,CAAC;IASlC,KAAK,GAEH,mBAAmB,SAAS,MAAM,SAAS,CAAC,OAAO,CAAC,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,QAG/E;QACE,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,mBAAmB,CAAC,CAAC,OAAO,CAAC,CAAA;QACvD,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;QACtB;;;;;;;WAOG;QACH,cAAc,CAAC,EAAE,OAAO,CAAA;QACxB;;;;;WAKG;QACH,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,GAAG,CAAC,EAAE,cAAc,CAAA;QACpB,IAAI,EAAE,mBAAmB,SAAS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;QACxB,GAAG,CAAC,EAAE,cAAc,CAAA;KACrB,KAAG,OAAO,CAAC,IAAI,CAAC;CA8BjB,CAAA"}
@@ -56,76 +56,73 @@ export const getJobsLocalAPI = (payload)=>({
56
56
  if (args.meta) {
57
57
  data.meta = args.meta;
58
58
  }
59
- // Compute concurrency key from workflow or task config (only if feature is enabled)
60
- if (payload.config.jobs?.enableConcurrencyControl) {
61
- let concurrencyKey = null;
62
- let supersedes = false;
63
- const queueName = queue || 'default';
64
- if (args.workflow) {
65
- const workflow = payload.config.jobs?.workflows?.find(({ slug })=>slug === args.workflow);
66
- if (workflow?.concurrency) {
67
- const concurrencyConfig = workflow.concurrency;
68
- if (typeof concurrencyConfig === 'function') {
69
- concurrencyKey = concurrencyConfig({
70
- input: args.input,
71
- queue: queueName
72
- });
73
- } else {
74
- concurrencyKey = concurrencyConfig.key({
75
- input: args.input,
76
- queue: queueName
77
- });
78
- supersedes = concurrencyConfig.supersedes ?? false;
79
- }
80
- }
81
- } else if (args.task) {
82
- const task = payload.config.jobs?.tasks?.find(({ slug })=>slug === args.task);
83
- if (task?.concurrency) {
84
- const concurrencyConfig = task.concurrency;
85
- if (typeof concurrencyConfig === 'function') {
86
- concurrencyKey = concurrencyConfig({
87
- input: args.input,
88
- queue: queueName
89
- });
90
- } else {
91
- concurrencyKey = concurrencyConfig.key({
92
- input: args.input,
93
- queue: queueName
94
- });
95
- supersedes = concurrencyConfig.supersedes ?? false;
96
- }
59
+ let concurrencyKey = null;
60
+ let supersedes = false;
61
+ const queueName = queue || 'default';
62
+ if (args.workflow) {
63
+ const workflow = payload.config.jobs?.workflows?.find(({ slug })=>slug === args.workflow);
64
+ if (workflow?.concurrency) {
65
+ const concurrencyConfig = workflow.concurrency;
66
+ if (typeof concurrencyConfig === 'function') {
67
+ concurrencyKey = concurrencyConfig({
68
+ input: args.input,
69
+ queue: queueName
70
+ });
71
+ } else {
72
+ concurrencyKey = concurrencyConfig.key({
73
+ input: args.input,
74
+ queue: queueName
75
+ });
76
+ supersedes = concurrencyConfig.supersedes ?? false;
97
77
  }
98
78
  }
99
- if (concurrencyKey) {
100
- data.concurrencyKey = concurrencyKey;
101
- // If supersedes is enabled, delete older pending jobs with the same key
102
- if (supersedes) {
103
- await payload.db.deleteMany({
104
- collection: jobsCollectionSlug,
105
- req,
106
- where: {
107
- and: [
108
- {
109
- concurrencyKey: {
110
- equals: concurrencyKey
111
- }
112
- },
113
- {
114
- processing: {
115
- equals: false
116
- }
117
- },
118
- {
119
- completedAt: {
120
- exists: false
121
- }
122
- }
123
- ]
124
- }
79
+ } else if (args.task) {
80
+ const task = payload.config.jobs?.tasks?.find(({ slug })=>slug === args.task);
81
+ if (task?.concurrency) {
82
+ const concurrencyConfig = task.concurrency;
83
+ if (typeof concurrencyConfig === 'function') {
84
+ concurrencyKey = concurrencyConfig({
85
+ input: args.input,
86
+ queue: queueName
125
87
  });
88
+ } else {
89
+ concurrencyKey = concurrencyConfig.key({
90
+ input: args.input,
91
+ queue: queueName
92
+ });
93
+ supersedes = concurrencyConfig.supersedes ?? false;
126
94
  }
127
95
  }
128
96
  }
97
+ if (concurrencyKey) {
98
+ data.concurrencyKey = concurrencyKey;
99
+ // If supersedes is enabled, delete older pending jobs with the same key
100
+ if (supersedes) {
101
+ await payload.db.deleteMany({
102
+ collection: jobsCollectionSlug,
103
+ req,
104
+ where: {
105
+ and: [
106
+ {
107
+ concurrencyKey: {
108
+ equals: concurrencyKey
109
+ }
110
+ },
111
+ {
112
+ processingUntil: {
113
+ exists: false
114
+ }
115
+ },
116
+ {
117
+ completedAt: {
118
+ exists: false
119
+ }
120
+ }
121
+ ]
122
+ }
123
+ });
124
+ }
125
+ }
129
126
  // Type assertion is still needed here
130
127
  return jobAfterRead({
131
128
  config: payload.config,
@@ -200,7 +197,7 @@ export const getJobsLocalAPI = (payload)=>({
200
197
  cancelled: true
201
198
  },
202
199
  hasError: true,
203
- processing: false,
200
+ processingUntil: null,
204
201
  waitUntil: null
205
202
  },
206
203
  req,
@@ -232,7 +229,7 @@ export const getJobsLocalAPI = (payload)=>({
232
229
  cancelled: true
233
230
  },
234
231
  hasError: true,
235
- processing: false,
232
+ processingUntil: null,
236
233
  waitUntil: null
237
234
  },
238
235
  req,