Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.2.0 #78

Merged
merged 27 commits into from
Nov 14, 2023
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fdc1c43
Add `TimeoutSeconds` and `TimeoutSecondsPath` fields to `Task` state …
nibble-4bits Oct 1, 2023
b424b2f
Throw `States.Timeout` error if `Task` state runs longer than time sp…
nibble-4bits Oct 1, 2023
62ae042
Update support for `TimeoutSeconds` and `TimeoutSecondsPath` fields
nibble-4bits Oct 1, 2023
191bcfa
Verify that `Task` state throws `States.Timeout` error on time out
nibble-4bits Oct 1, 2023
474d6e4
Merge pull request #73 from nibble-4bits/feature/task-state-timeout
nibble-4bits Oct 1, 2023
59ad614
Add support for `ItemProcessor` and `ItemSelector` fields of `Map` state
nibble-4bits Oct 2, 2023
9ed9f62
Add support for `MaxConcurrencyPath` field of `Map` state
nibble-4bits Oct 2, 2023
6d362b1
Update support for `ItemProcessor`, `ItemSelector`, and `MaxConcurren…
nibble-4bits Oct 2, 2023
b9dbacc
Verify that `Map` state works `ItemProcessor` and `ItemSelector` fields
nibble-4bits Oct 2, 2023
06059a9
Merge pull request #74 from nibble-4bits/feature/map-fields-item-sele…
nibble-4bits Oct 2, 2023
5bf7e1a
Create util `clamp` function
nibble-4bits Oct 3, 2023
5756548
Add support for `MaxDelaySeconds` field
nibble-4bits Oct 3, 2023
9071d29
Add support for `JitterStrategy` field
nibble-4bits Oct 3, 2023
885bcea
Update `RetryData` interface
nibble-4bits Oct 3, 2023
3e48711
Separate custom matchers declarations into `.d.ts` file
nibble-4bits Oct 15, 2023
098ab73
Create custom asymmetric matcher to test if a value is between two nu…
nibble-4bits Oct 15, 2023
01bcae0
Add tests for `MaxDelaySeconds` and `JitterStrategy` fields
nibble-4bits Oct 15, 2023
6786ed6
Merge pull request #75 from nibble-4bits/feature/retrier-jitterstrate…
nibble-4bits Oct 15, 2023
b6706f7
Add `CausePath` and `ErrorPath` fields to `Fail` state typing
nibble-4bits Oct 15, 2023
891e4f7
Add support for `ErrorPath` and `CausePath` fields
nibble-4bits Oct 15, 2023
eabf4b0
Add tests for `CausePath` and `ErrorPath` fields
nibble-4bits Oct 15, 2023
93a244b
Update constraint for `MaxConcurrencyPath` so it only allows non-nega…
nibble-4bits Oct 15, 2023
eb18d74
Merge pull request #76 from nibble-4bits/feature/failstate-errorpath-…
nibble-4bits Oct 16, 2023
14a174f
Update dependencies to latest version with `npm update`
nibble-4bits Oct 15, 2023
afea3cd
Merge pull request #77 from nibble-4bits/refactor-15
nibble-4bits Nov 14, 2023
a853b28
Document feature support for `ErrorPath`, `CausePath`, `MaxDelaySecon…
nibble-4bits Nov 14, 2023
480be0f
Bump package version to v1.2.0
nibble-4bits Nov 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add support for JitterStrategy field
  • Loading branch information
nibble-4bits committed Oct 3, 2023
commit 9071d29a3f9cff8a613419ec131a4a63cf6fe669
16 changes: 13 additions & 3 deletions src/stateMachine/StateExecutor.ts
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ import { SucceedStateAction } from './stateActions/SucceedStateAction';
import { TaskStateAction } from './stateActions/TaskStateAction';
import { WaitStateAction } from './stateActions/WaitStateAction';
import { StatesTimeoutError } from '../error/predefined/StatesTimeoutError';
import { clamp, sleep } from '../util';
import { clamp, sleep, getRandomNumber } from '../util';
import cloneDeep from 'lodash/cloneDeep.js';

/**
@@ -47,6 +47,11 @@ const DEFAULT_INTERVAL_SECONDS = 1;
*/
const DEFAULT_BACKOFF_RATE = 2.0;

/**
* Default jitter strategy for retry.
*/
const DEFAULT_JITTER_STRATEGY = 'NONE';

/**
* The wildcard error. This matches all thrown errors.
*/
@@ -223,13 +228,18 @@ export class StateExecutor {

for (let i = 0; i < this.stateDefinition.Retry.length; i++) {
const retrier = this.stateDefinition.Retry[i];
const jitterStrategy = retrier.JitterStrategy ?? DEFAULT_JITTER_STRATEGY;
const maxAttempts = retrier.MaxAttempts ?? DEFAULT_MAX_ATTEMPTS;
const intervalSeconds = retrier.IntervalSeconds ?? DEFAULT_INTERVAL_SECONDS;
const backoffRate = retrier.BackoffRate ?? DEFAULT_BACKOFF_RATE;
const waitInterval = intervalSeconds * Math.pow(backoffRate, this.retrierAttempts[i]) * 1000;
const waitTimeBeforeRetry = clamp(waitInterval, 1, retrier.MaxDelaySeconds);
const waitInterval = intervalSeconds * Math.pow(backoffRate, this.retrierAttempts[i]);
const retryable = error.isRetryable ?? true;

let waitTimeBeforeRetry = clamp(waitInterval, 1, retrier.MaxDelaySeconds) * 1000;
if (jitterStrategy === 'FULL') {
waitTimeBeforeRetry = getRandomNumber(0, waitTimeBeforeRetry);
}

for (const retrierError of retrier.ErrorEquals) {
const isErrorMatch = retrierError === error.name;
const isErrorWildcard = retrierError === WILDCARD_ERROR;
1 change: 1 addition & 0 deletions src/typings/ErrorHandling.ts
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ export type Retrier = {
MaxAttempts?: number; // default 3
BackoffRate?: number; // default 2.0
MaxDelaySeconds?: number;
JitterStrategy?: 'NONE' | 'FULL';
};

export interface RetryableState {