Skip to content

Commit

Permalink
Merge pull request #9 from leoShabalkin/change_retry_strategy
Browse files Browse the repository at this point in the history
fix(release): Change default retry strategy
  • Loading branch information
drwatsno authored Jun 10, 2020
2 parents bf9f452 + cc86c82 commit 8b7a907
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/retry-strategies/infinite.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import infiniteRetryStrategy from './infinite';

describe('#infiniteRetryStrategy', () => {
it('is a function', () => {
expect(typeof infiniteRetryStrategy).toBe('function');
});

it('returns a number', () => {
const delay = infiniteRetryStrategy(1);

expect(typeof delay).toBe('number');
expect(delay).toBe(1000);
});
});
4 changes: 2 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import EventEmitter from 'events';

import timeout from './timeout';
import randomPickConnectionString from './random-pick';
import infiniteRetryStrategy from './retry-strategies/infinite';
import {
EmptyMessageError,
AmqpConnectGracefullyStopped,
Expand All @@ -18,6 +17,7 @@ import { RawMessage, Message, MessageOptions, MessageHandlerOptions, MessageHand
import { ConnectionStatus } from './connection';
import { AMQPAdapter, AMQPOptions, AMQPConnection } from './adapters/amqp-node';
import { Logger } from './logger';
import defaultRetryStrategy from './retry-strategies/default';

const DEFAULT_HEART_BEAT = 30;

Expand Down Expand Up @@ -173,7 +173,7 @@ export class ServiceConnection extends EventEmitter {
* default one. Default retry strategy implements exponential backoff algorithm.
*/
async getConnection(attempt: number = 1): Promise<AMQPConnection> {
const { retryStrategy = infiniteRetryStrategy, maxReconnects = Infinity } = this.options;
const { retryStrategy = defaultRetryStrategy, maxReconnects = Infinity } = this.options;
let connection;

if (this.status === ConnectionStatus.DISCONNECTING) {
Expand Down

0 comments on commit 8b7a907

Please sign in to comment.