You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: ensure jobs do not retry indefinitely by default, fix undefined values in error messages (#9605)
## Fix default retries
By default, if no `retries` property has been set, jobs / tasks should
not be retried. This was not the case previously, as the `maxRetries`
variable was `undefined`, causing jobs to retry endlessly. This PR sets
them to `0` by default.
Additionally, this fixes some undesirable behavior of the workflow
retries property. Workflow retries now act as **maximum**,
workflow-level retries. Only tasks that do not have a retry property set
will inherit the workflow-level retries.
## Fix error messages
Previously, you were able to encounter error messages with undefined
values like these:

Reason is that it was always using `job.workflowSlug` for the error
messages. However, if you queue a task directly, without a workflow,
`job.workflowSlug` is undefined and `job.taskSlug` should be used
instead.
This PR then gets rid of the second undefined value by ensuring that
`maxRetries´ is never undefined
Copy file name to clipboardExpand all lines: docs/jobs-queue/tasks.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ Simply add a task to the `jobs.tasks` array in your Payload config. A task consi
30
30
|`label`| Define a human-friendly label for this task. |
31
31
|`onFail`| Function to be executed if the task fails. |
32
32
|`onSuccess`| Function to be executed if the task succeeds. |
33
-
|`retries`| Specify the number of times that this step should be retried if it fails. |
33
+
|`retries`| Specify the number of times that this step should be retried if it fails. If this is undefined, the task will either inherit the retries from the workflow or have no retries. If this is 0, the task will not be retried. By default, this is undefined. |
34
34
35
35
The logic for the Task is defined in the `handler` - which can be defined as a function, or a path to a function. The `handler` will run once a worker picks picks up a Job that includes this task.
Copy file name to clipboardExpand all lines: docs/jobs-queue/workflows.mdx
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: Workflows
3
3
label: Workflows
4
4
order: 30
5
-
desc: A Task is a distinct function declaration that can be run within Payload's Jobs Queue.
5
+
desc: A Task is a distinct function declaration that can be run within Payload's Jobs Queue.
6
6
keywords: jobs queue, application framework, typescript, node, react, nextjs
7
7
---
8
8
@@ -30,6 +30,7 @@ To define a JS-based workflow, simply add a workflow to the `jobs.wokflows` arra
30
30
|`interfaceName`| 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. |
31
31
|`label`| Define a human-friendly label for this workflow. |
32
32
|`queue`| Optionally, define the queue name that this workflow should be tied to. Defaults to "default". |
33
+
|`retries`| 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. You can specify `0` as `workflow` retries, which will disregard all `task` retry specifications and fail the entire workflow on any task failure. You can leave `workflow` retries as undefined, in which case, the workflow will respect what each task dictates as their own retry count. By default this is undefined, meaning workflows retries are defined by their tasks |
Copy file name to clipboardExpand all lines: packages/payload/src/queues/config/types/workflowTypes.ts
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -114,9 +114,14 @@ export type WorkflowConfig<TWorkflowSlugOrInput extends keyof TypedJobs['workflo
114
114
*/
115
115
queue?: string
116
116
/**
117
-
* Specify the number of times that this workflow should be retried if it fails for any reason.
117
+
* 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.
118
+
*
119
+
* You can specify `0` as `workflow` retries, which will disregard all `task` retry specifications and fail the entire workflow on any task failure.
120
+
* You can leave `workflow` retries as undefined, in which case, the workflow will respect what each task dictates as their own retry count.
121
+
*
122
+
* @default undefined. By default, workflows retries are defined by their tasks
0 commit comments