|
1 | 1 | using Temporalio.Api.Enums.V1; |
| 2 | +using Temporalio.Common; |
2 | 3 |
|
3 | 4 | namespace Temporalio.Tests; |
4 | 5 |
|
@@ -55,6 +56,16 @@ public class KitchenSinkWorkflow |
55 | 56 |
|
56 | 57 | public Task SomeSignalAsync(string arg) => Task.CompletedTask; |
57 | 58 |
|
| 59 | + public static RetryPolicy CreateRetryPolicy(int? maximumAttempts = null, IReadOnlyCollection<string>? nonRetryableErrorTypes = null) => |
| 60 | + new() |
| 61 | + { |
| 62 | + InitialInterval = TimeSpan.FromMilliseconds(1), |
| 63 | + BackoffCoefficient = 1.01F, |
| 64 | + MaximumInterval = TimeSpan.FromMilliseconds(2), |
| 65 | + MaximumAttempts = maximumAttempts ?? 1, |
| 66 | + NonRetryableErrorTypes = nonRetryableErrorTypes, |
| 67 | + }; |
| 68 | + |
58 | 69 | private async Task<(bool ShouldReturn, object? Value)> HandleActionAsync( |
59 | 70 | KSWorkflowParams args, KSAction action) |
60 | 71 | { |
@@ -144,14 +155,7 @@ action with |
144 | 155 | var opts = new ActivityOptions() |
145 | 156 | { |
146 | 157 | TaskQueue = action.ExecuteActivity.TaskQueue, |
147 | | - RetryPolicy = new() |
148 | | - { |
149 | | - InitialInterval = TimeSpan.FromMilliseconds(1), |
150 | | - BackoffCoefficient = 1.01F, |
151 | | - MaximumInterval = TimeSpan.FromMilliseconds(2), |
152 | | - MaximumAttempts = 1, |
153 | | - NonRetryableErrorTypes = action.ExecuteActivity.NonRetryableErrorTypes ?? Array.Empty<string>(), |
154 | | - }, |
| 158 | + RetryPolicy = CreateRetryPolicy(action.ExecuteActivity.RetryMaxAttempts, action.ExecuteActivity.NonRetryableErrorTypes), |
155 | 159 | }; |
156 | 160 | if (action.ExecuteActivity.ScheduleToCloseTimeoutMS != null) |
157 | 161 | { |
@@ -182,10 +186,6 @@ action with |
182 | 186 | { |
183 | 187 | opts.ScheduleToCloseTimeout = TimeSpan.FromMinutes(3); |
184 | 188 | } |
185 | | - if (action.ExecuteActivity.RetryMaxAttempts != null) |
186 | | - { |
187 | | - opts.RetryPolicy.MaximumAttempts = action.ExecuteActivity.RetryMaxAttempts.Value; |
188 | | - } |
189 | 189 | // Build cancellation token source for delayed cancelling |
190 | 190 | using var cancelSource = CancellationTokenSource.CreateLinkedTokenSource( |
191 | 191 | Workflow.CancellationToken); |
|
0 commit comments