Skip to content

Commit 31d6f34

Browse files
authored
fix: Allow RetryPolicy.maximumAttempts: Number.POSITIVE_INFINITY (#784)
1 parent ea10020 commit 31d6f34

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,11 @@ npx lerna version patch # or major|minor|etc, or leave out to be prompted. eithe
193193
npx lerna publish from-git # add `--dist-tag next` for pre-release versions
194194
```
195195

196-
- Cleanup:
196+
- Cleanup after publishing:
197197

198198
```sh
199199
rm $HOME/Downloads/packages-*
200+
rm packages/core-bridge/releases/
200201
```
201202

202203
## Updating the Java test server proto files

packages/internal-workflow-common/src/retry-policy.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ export interface RetryPolicy {
2121
*/
2222
initialInterval?: string | number;
2323
/**
24-
* Maximum number of attempts. When exceeded the retries stop even if not expired yet.
25-
* @minimum 1
24+
* Maximum number of attempts. When exceeded, retries stop (even if {@link ActivityOptions.scheduleToCloseTimeout}
25+
* hasn't been reached).
26+
*
2627
* @default Infinity
2728
*/
2829
maximumAttempts?: number;
@@ -50,11 +51,13 @@ export function compileRetryPolicy(retryPolicy: RetryPolicy): temporal.api.commo
5051
throw new ValueError('RetryPolicy.backoffCoefficient must be greater than 0');
5152
}
5253
if (retryPolicy.maximumAttempts != null) {
53-
if (retryPolicy.maximumAttempts <= 0) {
54-
throw new ValueError('RetryPolicy.maximumAttempts must be greater than 0');
55-
}
56-
57-
if (!Number.isInteger(retryPolicy.maximumAttempts)) {
54+
if (retryPolicy.maximumAttempts === Number.POSITIVE_INFINITY) {
55+
// drop field (Infinity is the default)
56+
const { maximumAttempts: _, ...without } = retryPolicy;
57+
retryPolicy = without;
58+
} else if (retryPolicy.maximumAttempts <= 0) {
59+
throw new ValueError('RetryPolicy.maximumAttempts must be a positive integer');
60+
} else if (!Number.isInteger(retryPolicy.maximumAttempts)) {
5861
throw new ValueError('RetryPolicy.maximumAttempts must be an integer');
5962
}
6063
}

packages/test/src/test-retry-policy.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ test('compileRetryPolicy validates backoffCoefficient is greater than 0', (t) =>
3535
});
3636
});
3737

38-
test('compileRetryPolicy validates maximumAttempts greater than 0', (t) => {
39-
t.throws(() => compileRetryPolicy({ maximumAttempts: 0 }), {
38+
test('compileRetryPolicy validates maximumAttempts is positive', (t) => {
39+
t.throws(() => compileRetryPolicy({ maximumAttempts: -1 }), {
4040
instanceOf: ValueError,
41-
message: 'RetryPolicy.maximumAttempts must be greater than 0',
41+
message: 'RetryPolicy.maximumAttempts must be a positive integer',
4242
});
4343
});
4444

@@ -49,11 +49,8 @@ test('compileRetryPolicy validates maximumAttempts is an integer', (t) => {
4949
});
5050
});
5151

52-
test('compileRetryPolicy validates maximumAttempts is not POSITIVE_INFINITY', (t) => {
53-
t.throws(() => compileRetryPolicy({ maximumAttempts: Number.POSITIVE_INFINITY }), {
54-
instanceOf: ValueError,
55-
message: 'RetryPolicy.maximumAttempts must be an integer',
56-
});
52+
test('compileRetryPolicy drops maximumAttempts when POSITIVE_INFINITY', (t) => {
53+
t.deepEqual(compileRetryPolicy({ maximumAttempts: Number.POSITIVE_INFINITY }), compileRetryPolicy({}));
5754
});
5855

5956
test('compileRetryPolicy defaults initialInterval to 1 second', (t) => {

0 commit comments

Comments
 (0)