Skip to content

Commit

Permalink
fix(backoff): change optional BackoffStrategy params to use union (#2365
Browse files Browse the repository at this point in the history
)
  • Loading branch information
roggervalf authored Sep 17, 2024
1 parent 8eed71d commit 29e454a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/repeat-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface RepeatOptions extends Omit<ParserOptions, 'iterator'> {
every?: number;
/**
* Repeated job should start right now
* ( work only with every settings)
* (work only with every settings)
*/
immediately?: boolean;
/**
Expand Down
30 changes: 26 additions & 4 deletions src/types/backoff-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
import { MinimalJob } from '../interfaces/minimal-job';

export type BackoffStrategy = (
export type BackoffStrategy4 = (
attemptsMade: number,
type?: string,
err?: Error,
job?: MinimalJob,
type: string,
err: Error,
job: MinimalJob,
) => Promise<number> | number;

export type BackoffStrategy3 = (
attemptsMade: number,
type: string,
err: Error,
) => Promise<number> | number;

export type BackoffStrategy2 = (
attemptsMade: number,
type: string,
) => Promise<number> | number;

export type BackoffStrategy1 = (attemptsMade: number) => Promise<number> | number;

export type BackoffStrategy0 = () => Promise<number> | number;

export type BackoffStrategy =
| BackoffStrategy4
| BackoffStrategy3
| BackoffStrategy2
| BackoffStrategy1
| BackoffStrategy0;
7 changes: 1 addition & 6 deletions tests/test_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3589,12 +3589,7 @@ describe('workers', function () {
connection,
prefix,
settings: {
backoffStrategy: (
attemptsMade: number,
type: string,
err: Error,
job: MinimalJob,
) => {
backoffStrategy: (attemptsMade: number, type: string) => {
switch (type) {
case 'custom1': {
return attemptsMade * 1000;
Expand Down

0 comments on commit 29e454a

Please sign in to comment.