@wavezync/nestjs-pgboss 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,13 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleRetry = handleRetry;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const operators_1 = require("rxjs/operators");
6
+ const consts_1 = require("./consts");
7
+ const common_1 = require("@nestjs/common");
6
8
  function handleRetry(retryAttempts = 9, retryDelay = 3000, verbose = false, toRetry = (_err) => true) {
7
- return (source) => source.pipe((0, operators_1.retryWhen)((attempts) => attempts.pipe((0, operators_1.take)(retryAttempts), (0, operators_1.mergeMap)((error, index) => {
9
+ const logger = new common_1.Logger(consts_1.LOGGER);
10
+ return (source) => source.pipe((0, operators_1.retryWhen)((attempts) => attempts.pipe((0, operators_1.mergeMap)((error, index) => {
8
11
  const includeError = toRetry(error);
9
- if (verbose && includeError) {
10
- console.warn(`Attempt ${index + 1}: Retrying in ${retryDelay / 1000} seconds...`);
12
+ if (includeError) {
13
+ if (verbose) {
14
+ logger.warn(`Attempt ${index + 1}: Retrying in ${retryDelay / 1000} seconds...`);
15
+ }
16
+ if (index + 1 >= retryAttempts) {
17
+ return (0, rxjs_1.throwError)(() => new Error(error.message));
18
+ }
19
+ return (0, rxjs_1.of)(error).pipe((0, operators_1.delay)(retryDelay));
11
20
  }
12
- return includeError ? (0, rxjs_1.of)(error) : (0, rxjs_1.throwError)(error);
13
- }), (0, operators_1.delay)(retryDelay))));
21
+ return (0, rxjs_1.throwError)(() => error);
22
+ }))));
14
23
  }
15
24
  //# sourceMappingURL=handleRetry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"handleRetry.js","sourceRoot":"","sources":["../../lib/utils/handleRetry.ts"],"names":[],"mappings":";;AAGA,kCA0BC;AA7BD,+BAAsC;AACtC,8CAAkE;AAElE,SAAgB,WAAW,CACzB,aAAa,GAAG,CAAC,EACjB,UAAU,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,oBAAQ,EAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACxB,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;QAEpC,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,CAAC,IAAI,CACT,WAAW,KAAK,GAAG,CAAC,iBAClB,UAAU,GAAG,IACf,aAAa,CACd,CAAC;YACJ,CAAC;YAED,IAAI,KAAK,GAAG,CAAC,IAAI,aAAa,EAAE,CAAC;gBAC/B,OAAO,IAAA,iBAAU,EAAC,GAAG,EAAE,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;YACpD,CAAC;YAED,OAAO,IAAA,SAAE,EAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAA,iBAAK,EAAC,UAAU,CAAC,CAAC,CAAC;QAC3C,CAAC;QAED,OAAO,IAAA,iBAAU,EAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC,CACH,CACF,CACF,CAAC;AACN,CAAC"}
@@ -1,5 +1,7 @@
1
1
  import { of, throwError } from "rxjs";
2
- import { mergeMap, retryWhen, take, delay } from "rxjs/operators";
2
+ import { mergeMap, retryWhen, delay } from "rxjs/operators";
3
+ import { LOGGER } from "./consts";
4
+ import { Logger } from "@nestjs/common";
3
5
 
4
6
  export function handleRetry(
5
7
  retryAttempts = 9,
@@ -7,23 +9,33 @@ export function handleRetry(
7
9
  verbose = false,
8
10
  toRetry: (err: any) => boolean = (_err: any) => true,
9
11
  ) {
12
+ const logger = new Logger(LOGGER);
13
+
10
14
  return <T>(source: import("rxjs").Observable<T>) =>
11
15
  source.pipe(
12
16
  retryWhen((attempts) =>
13
17
  attempts.pipe(
14
- take(retryAttempts),
15
18
  mergeMap((error, index) => {
16
19
  const includeError = toRetry(error);
17
- if (verbose && includeError) {
18
- console.warn(
19
- `Attempt ${index + 1}: Retrying in ${
20
- retryDelay / 1000
21
- } seconds...`,
22
- );
20
+
21
+ if (includeError) {
22
+ if (verbose) {
23
+ logger.warn(
24
+ `Attempt ${index + 1}: Retrying in ${
25
+ retryDelay / 1000
26
+ } seconds...`,
27
+ );
28
+ }
29
+
30
+ if (index + 1 >= retryAttempts) {
31
+ return throwError(() => new Error(error.message));
32
+ }
33
+
34
+ return of(error).pipe(delay(retryDelay));
23
35
  }
24
- return includeError ? of(error) : throwError(error);
36
+
37
+ return throwError(() => error);
25
38
  }),
26
- delay(retryDelay),
27
39
  ),
28
40
  ),
29
41
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wavezync/nestjs-pgboss",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "A NestJS module that integrates pg-boss for job scheduling and handling.",
5
5
  "license": "MIT",
6
6
  "author": "samaratungajs@wavezync.com",