Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should return true for retryable errors', () => {
[
status.OK,
status.CANCELLED,
status.UNKNOWN,
status.DEADLINE_EXCEEDED,
status.RESOURCE_EXHAUSTED,
status.ABORTED,
status.INTERNAL,
status.UNAVAILABLE,
status.DATA_LOSS,
].forEach((code: status) => {
const shouldRetry = retrier.retry({code} as StatusObject);
assert.strictEqual(shouldRetry, true);
});
});
*/
import {StatusObject, status} from '@grpc/grpc-js';
/*!
* retryable status codes
*/
export const RETRY_CODES: status[] = [
status.OK,
status.CANCELLED,
status.UNKNOWN,
status.DEADLINE_EXCEEDED,
status.RESOURCE_EXHAUSTED,
status.ABORTED,
status.INTERNAL,
status.UNAVAILABLE,
status.DATA_LOSS,
];
/**
* Used to track pull requests and determine if additional requests should be
* made, etc.
*
* @class
* @private
*/
export class PullRetry {
private failures = 0;
/**
* Generates a timeout that can be used for applying a backoff based on the
* current number of failed requests.
*
* @see {@link https://cloud.google.com/iot/docs/how-tos/exponential-backoff}