@vasrefil/api-toolkit 1.7.5 → 1.7.7

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.
@@ -1,5 +1,12 @@
1
- export declare const connection: any;
1
+ import IORedis from 'ioredis';
2
2
  export declare enum JOB {
3
3
  EMAIL = "EMAIL",
4
4
  IN_APP_NOTIFICATION = "IN_APP_NOTIFICATION"
5
5
  }
6
+ declare class BullmqClient_ {
7
+ private connection;
8
+ init: () => void;
9
+ getConnection(): IORedis;
10
+ }
11
+ export declare const BullmqClient: BullmqClient_;
12
+ export {};
@@ -3,12 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.JOB = exports.connection = void 0;
7
- const IORedis = require('ioredis');
6
+ exports.BullmqClient = exports.JOB = void 0;
7
+ const ioredis_1 = __importDefault(require("ioredis"));
8
8
  const env_1 = __importDefault(require("../env"));
9
- exports.connection = new IORedis(env_1.default.BULLMQ_REDIS_URL, { maxRetriesPerRequest: null });
10
9
  var JOB;
11
10
  (function (JOB) {
12
11
  JOB["EMAIL"] = "EMAIL";
13
12
  JOB["IN_APP_NOTIFICATION"] = "IN_APP_NOTIFICATION";
14
13
  })(JOB || (exports.JOB = JOB = {}));
14
+ class BullmqClient_ {
15
+ constructor() {
16
+ this.init = () => {
17
+ try {
18
+ this.connection = new ioredis_1.default(env_1.default.BULLMQ_REDIS_URL, { maxRetriesPerRequest: null });
19
+ this.connection.on('error', (err) => console.log('BullmqRedis-error', err));
20
+ this.connection.on('connect', () => console.log('BullmqRedis server connected...'));
21
+ }
22
+ catch (error) {
23
+ console.log(error);
24
+ }
25
+ };
26
+ }
27
+ getConnection() {
28
+ return this.connection;
29
+ }
30
+ }
31
+ exports.BullmqClient = new BullmqClient_;
@@ -1,3 +1,3 @@
1
1
  import { Queue } from 'bullmq';
2
- export declare const EmailQueue: Queue<any, any, string, any, any, string>;
3
- export declare const InAppNotificationQueue: Queue<any, any, string, any, any, string>;
2
+ export declare const EmailQueue: () => Queue<any, any, string, any, any, string>;
3
+ export declare const InAppNotificationQueue: () => Queue<any, any, string, any, any, string>;
@@ -8,6 +8,7 @@ const bullmq_1 = require("bullmq");
8
8
  const common_1 = require("./common");
9
9
  const common_2 = require("./common");
10
10
  const env_1 = __importDefault(require("../env"));
11
+ const connection = common_1.BullmqClient.getConnection();
11
12
  const attempts = env_1.default.NODE_ENV === env_1.default.NODE_ENVS.PROD ? 10 : 1;
12
13
  const removeOnComplete = {
13
14
  age: (3600 * 24) * 3, // 3 days
@@ -16,20 +17,22 @@ const backoff = {
16
17
  type: 'exponential',
17
18
  delay: 10000,
18
19
  };
19
- exports.EmailQueue = new bullmq_1.Queue(common_2.JOB.EMAIL, {
20
- connection: common_1.connection,
21
- defaultJobOptions: {
20
+ const EmailQueue = () => {
21
+ const defaultJobOptions = {
22
22
  attempts,
23
23
  backoff,
24
24
  removeOnComplete
25
- },
26
- });
27
- exports.InAppNotificationQueue = new bullmq_1.Queue(common_2.JOB.IN_APP_NOTIFICATION, {
28
- connection: common_1.connection,
29
- defaultJobOptions: {
25
+ };
26
+ return new bullmq_1.Queue(common_2.JOB.EMAIL, { connection, defaultJobOptions });
27
+ };
28
+ exports.EmailQueue = EmailQueue;
29
+ const InAppNotificationQueue = () => {
30
+ const defaultJobOptions = {
30
31
  attempts: 1,
31
32
  backoff,
32
33
  removeOnComplete,
33
34
  removeOnFail: removeOnComplete
34
- },
35
- });
35
+ };
36
+ return new bullmq_1.Queue(common_2.JOB.IN_APP_NOTIFICATION, { connection, defaultJobOptions });
37
+ };
38
+ exports.InAppNotificationQueue = InAppNotificationQueue;
@@ -7,7 +7,7 @@ class EmailUtil_ {
7
7
  constructor() {
8
8
  this.send_email = async (payload) => {
9
9
  try {
10
- queue_1.EmailQueue.add(payload.action_type, {
10
+ (0, queue_1.EmailQueue)().add(payload.action_type, {
11
11
  ...payload,
12
12
  });
13
13
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vasrefil/api-toolkit",
3
3
  "description": "This is Vasrefil API toolkit",
4
- "version": "1.7.5",
4
+ "version": "1.7.7",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",