@forklaunch/implementation-worker-bullmq 0.3.1 → 0.3.3

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,19 +1,32 @@
1
1
  import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
2
- import { WorkerEventEntity, WorkerProcessFunction, WorkerFailureHandler } from '@forklaunch/interfaces-worker/types';
3
- import { BullMqWorkerOptions } from '../types/index.mjs';
2
+ import {
3
+ WorkerEventEntity,
4
+ WorkerProcessFunction,
5
+ WorkerFailureHandler
6
+ } from '@forklaunch/interfaces-worker/types';
7
+ import { BullMqWorkerOptions } from '../domain/types/index.mjs';
4
8
  import 'bullmq';
5
9
 
6
- declare class BullMqWorkerConsumer<EventEntity extends WorkerEventEntity, Options extends BullMqWorkerOptions> implements WorkerConsumer<EventEntity> {
7
- protected readonly queueName: string;
8
- protected readonly options: Options;
9
- protected readonly processEvents: WorkerProcessFunction<EventEntity>;
10
- protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
11
- private queue;
12
- private worker?;
13
- constructor(queueName: string, options: Options, processEvents: WorkerProcessFunction<EventEntity>, failureHandler: WorkerFailureHandler<EventEntity>);
14
- peekEvents(): Promise<EventEntity[]>;
15
- start(): Promise<void>;
16
- close(): Promise<void>;
10
+ declare class BullMqWorkerConsumer<
11
+ EventEntity extends WorkerEventEntity,
12
+ Options extends BullMqWorkerOptions
13
+ > implements WorkerConsumer<EventEntity>
14
+ {
15
+ protected readonly queueName: string;
16
+ protected readonly options: Options;
17
+ protected readonly processEvents: WorkerProcessFunction<EventEntity>;
18
+ protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
19
+ private queue;
20
+ private worker?;
21
+ constructor(
22
+ queueName: string,
23
+ options: Options,
24
+ processEvents: WorkerProcessFunction<EventEntity>,
25
+ failureHandler: WorkerFailureHandler<EventEntity>
26
+ );
27
+ peekEvents(): Promise<EventEntity[]>;
28
+ start(): Promise<void>;
29
+ close(): Promise<void>;
17
30
  }
18
31
 
19
32
  export { BullMqWorkerConsumer };
@@ -1,19 +1,32 @@
1
1
  import { WorkerConsumer } from '@forklaunch/interfaces-worker/interfaces';
2
- import { WorkerEventEntity, WorkerProcessFunction, WorkerFailureHandler } from '@forklaunch/interfaces-worker/types';
3
- import { BullMqWorkerOptions } from '../types/index.js';
2
+ import {
3
+ WorkerEventEntity,
4
+ WorkerProcessFunction,
5
+ WorkerFailureHandler
6
+ } from '@forklaunch/interfaces-worker/types';
7
+ import { BullMqWorkerOptions } from '../domain/types/index.js';
4
8
  import 'bullmq';
5
9
 
6
- declare class BullMqWorkerConsumer<EventEntity extends WorkerEventEntity, Options extends BullMqWorkerOptions> implements WorkerConsumer<EventEntity> {
7
- protected readonly queueName: string;
8
- protected readonly options: Options;
9
- protected readonly processEvents: WorkerProcessFunction<EventEntity>;
10
- protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
11
- private queue;
12
- private worker?;
13
- constructor(queueName: string, options: Options, processEvents: WorkerProcessFunction<EventEntity>, failureHandler: WorkerFailureHandler<EventEntity>);
14
- peekEvents(): Promise<EventEntity[]>;
15
- start(): Promise<void>;
16
- close(): Promise<void>;
10
+ declare class BullMqWorkerConsumer<
11
+ EventEntity extends WorkerEventEntity,
12
+ Options extends BullMqWorkerOptions
13
+ > implements WorkerConsumer<EventEntity>
14
+ {
15
+ protected readonly queueName: string;
16
+ protected readonly options: Options;
17
+ protected readonly processEvents: WorkerProcessFunction<EventEntity>;
18
+ protected readonly failureHandler: WorkerFailureHandler<EventEntity>;
19
+ private queue;
20
+ private worker?;
21
+ constructor(
22
+ queueName: string,
23
+ options: Options,
24
+ processEvents: WorkerProcessFunction<EventEntity>,
25
+ failureHandler: WorkerFailureHandler<EventEntity>
26
+ );
27
+ peekEvents(): Promise<EventEntity[]>;
28
+ start(): Promise<void>;
29
+ close(): Promise<void>;
17
30
  }
18
31
 
19
32
  export { BullMqWorkerConsumer };
@@ -1,4 +1,4 @@
1
- "use strict";
1
+ 'use strict';
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -8,14 +8,18 @@ var __export = (target, all) => {
8
8
  __defProp(target, name, { get: all[name], enumerable: true });
9
9
  };
10
10
  var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
11
+ if ((from && typeof from === 'object') || typeof from === 'function') {
12
12
  for (let key of __getOwnPropNames(from))
13
13
  if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
15
18
  }
16
19
  return to;
17
20
  };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var __toCommonJS = (mod) =>
22
+ __copyProps(__defProp({}, '__esModule', { value: true }), mod);
19
23
 
20
24
  // consumers/index.ts
21
25
  var consumers_exports = {};
@@ -25,7 +29,7 @@ __export(consumers_exports, {
25
29
  module.exports = __toCommonJS(consumers_exports);
26
30
 
27
31
  // consumers/bullMqWorker.consumer.ts
28
- var import_bullmq = require("bullmq");
32
+ var import_bullmq = require('bullmq');
29
33
  var BullMqWorkerConsumer = class {
30
34
  constructor(queueName, options, processEvents, failureHandler) {
31
35
  this.queueName = queueName;
@@ -33,13 +37,13 @@ var BullMqWorkerConsumer = class {
33
37
  this.processEvents = processEvents;
34
38
  this.failureHandler = failureHandler;
35
39
  this.queue = new import_bullmq.Queue(this.queueName, {
36
- connection: this.options.connection
40
+ connection: this.options.queueOptions.connection
37
41
  });
38
42
  }
39
43
  queue;
40
44
  worker;
41
45
  async peekEvents() {
42
- const jobs = await this.queue.getJobs(["waiting", "active"]);
46
+ const jobs = await this.queue.getJobs(['waiting', 'active']);
43
47
  return jobs.map((job) => job.data);
44
48
  }
45
49
  async start() {
@@ -49,9 +53,9 @@ var BullMqWorkerConsumer = class {
49
53
  const event = job.data;
50
54
  await this.processEvents([event]);
51
55
  },
52
- this.options
56
+ this.options.queueOptions
53
57
  );
54
- this.worker.on("failed", (job, error) => {
58
+ this.worker.on('failed', (job, error) => {
55
59
  if (job) {
56
60
  this.failureHandler([
57
61
  {
@@ -68,6 +72,7 @@ var BullMqWorkerConsumer = class {
68
72
  }
69
73
  };
70
74
  // Annotate the CommonJS export names for ESM import in node:
71
- 0 && (module.exports = {
72
- BullMqWorkerConsumer
73
- });
75
+ 0 &&
76
+ (module.exports = {
77
+ BullMqWorkerConsumer
78
+ });
@@ -1,5 +1,5 @@
1
1
  // consumers/bullMqWorker.consumer.ts
2
- import { Queue, Worker } from "bullmq";
2
+ import { Queue, Worker } from 'bullmq';
3
3
  var BullMqWorkerConsumer = class {
4
4
  constructor(queueName, options, processEvents, failureHandler) {
5
5
  this.queueName = queueName;
@@ -7,13 +7,13 @@ var BullMqWorkerConsumer = class {
7
7
  this.processEvents = processEvents;
8
8
  this.failureHandler = failureHandler;
9
9
  this.queue = new Queue(this.queueName, {
10
- connection: this.options.connection
10
+ connection: this.options.queueOptions.connection
11
11
  });
12
12
  }
13
13
  queue;
14
14
  worker;
15
15
  async peekEvents() {
16
- const jobs = await this.queue.getJobs(["waiting", "active"]);
16
+ const jobs = await this.queue.getJobs(['waiting', 'active']);
17
17
  return jobs.map((job) => job.data);
18
18
  }
19
19
  async start() {
@@ -23,9 +23,9 @@ var BullMqWorkerConsumer = class {
23
23
  const event = job.data;
24
24
  await this.processEvents([event]);
25
25
  },
26
- this.options
26
+ this.options.queueOptions
27
27
  );
28
- this.worker.on("failed", (job, error) => {
28
+ this.worker.on('failed', (job, error) => {
29
29
  if (job) {
30
30
  this.failureHandler([
31
31
  {
@@ -41,6 +41,4 @@ var BullMqWorkerConsumer = class {
41
41
  await this.queue.close();
42
42
  }
43
43
  };
44
- export {
45
- BullMqWorkerConsumer
46
- };
44
+ export { BullMqWorkerConsumer };
@@ -0,0 +1,67 @@
1
+ import * as _forklaunch_internal from '@forklaunch/internal';
2
+ import * as zod from 'zod';
3
+ import * as bullmq from 'bullmq';
4
+ import * as _sinclair_typebox from '@sinclair/typebox';
5
+ import * as _forklaunch_validator from '@forklaunch/validator';
6
+
7
+ declare const BullMqWorkerSchemas: <
8
+ SchemaValidator extends _forklaunch_validator.AnySchemaValidator
9
+ >(
10
+ options: Record<string, unknown> & {
11
+ validator: SchemaValidator;
12
+ }
13
+ ) => _forklaunch_internal.SchemasByValidator<
14
+ SchemaValidator,
15
+ (options: Record<string, unknown>) => {
16
+ queueOptions: _sinclair_typebox.TTransform<
17
+ _sinclair_typebox.TAny,
18
+ bullmq.QueueOptions
19
+ >;
20
+ backoffType: _sinclair_typebox.TUnion<
21
+ [
22
+ _sinclair_typebox.TLiteral<'exponential'>,
23
+ _sinclair_typebox.TLiteral<'fixed'>
24
+ ]
25
+ >;
26
+ retries: _sinclair_typebox.TTransform<
27
+ _sinclair_typebox.TUnion<
28
+ [
29
+ _sinclair_typebox.TNumber,
30
+ _sinclair_typebox.TString,
31
+ _sinclair_typebox.TBoolean,
32
+ _sinclair_typebox.TNull,
33
+ _sinclair_typebox.TBigInt,
34
+ _sinclair_typebox.TDate
35
+ ]
36
+ >,
37
+ number
38
+ >;
39
+ interval: _sinclair_typebox.TTransform<
40
+ _sinclair_typebox.TUnion<
41
+ [
42
+ _sinclair_typebox.TNumber,
43
+ _sinclair_typebox.TString,
44
+ _sinclair_typebox.TBoolean,
45
+ _sinclair_typebox.TNull,
46
+ _sinclair_typebox.TBigInt,
47
+ _sinclair_typebox.TDate
48
+ ]
49
+ >,
50
+ number
51
+ >;
52
+ },
53
+ (options: Record<string, unknown>) => {
54
+ queueOptions: zod.ZodType<
55
+ bullmq.QueueOptions,
56
+ zod.ZodTypeDef,
57
+ bullmq.QueueOptions
58
+ >;
59
+ backoffType: zod.ZodUnion<
60
+ [zod.ZodLiteral<'exponential'>, zod.ZodLiteral<'fixed'>]
61
+ >;
62
+ retries: zod.ZodEffects<zod.ZodNumber, number, unknown>;
63
+ interval: zod.ZodEffects<zod.ZodNumber, number, unknown>;
64
+ }
65
+ >;
66
+
67
+ export { BullMqWorkerSchemas };
@@ -0,0 +1,67 @@
1
+ import * as _forklaunch_internal from '@forklaunch/internal';
2
+ import * as zod from 'zod';
3
+ import * as bullmq from 'bullmq';
4
+ import * as _sinclair_typebox from '@sinclair/typebox';
5
+ import * as _forklaunch_validator from '@forklaunch/validator';
6
+
7
+ declare const BullMqWorkerSchemas: <
8
+ SchemaValidator extends _forklaunch_validator.AnySchemaValidator
9
+ >(
10
+ options: Record<string, unknown> & {
11
+ validator: SchemaValidator;
12
+ }
13
+ ) => _forklaunch_internal.SchemasByValidator<
14
+ SchemaValidator,
15
+ (options: Record<string, unknown>) => {
16
+ queueOptions: _sinclair_typebox.TTransform<
17
+ _sinclair_typebox.TAny,
18
+ bullmq.QueueOptions
19
+ >;
20
+ backoffType: _sinclair_typebox.TUnion<
21
+ [
22
+ _sinclair_typebox.TLiteral<'exponential'>,
23
+ _sinclair_typebox.TLiteral<'fixed'>
24
+ ]
25
+ >;
26
+ retries: _sinclair_typebox.TTransform<
27
+ _sinclair_typebox.TUnion<
28
+ [
29
+ _sinclair_typebox.TNumber,
30
+ _sinclair_typebox.TString,
31
+ _sinclair_typebox.TBoolean,
32
+ _sinclair_typebox.TNull,
33
+ _sinclair_typebox.TBigInt,
34
+ _sinclair_typebox.TDate
35
+ ]
36
+ >,
37
+ number
38
+ >;
39
+ interval: _sinclair_typebox.TTransform<
40
+ _sinclair_typebox.TUnion<
41
+ [
42
+ _sinclair_typebox.TNumber,
43
+ _sinclair_typebox.TString,
44
+ _sinclair_typebox.TBoolean,
45
+ _sinclair_typebox.TNull,
46
+ _sinclair_typebox.TBigInt,
47
+ _sinclair_typebox.TDate
48
+ ]
49
+ >,
50
+ number
51
+ >;
52
+ },
53
+ (options: Record<string, unknown>) => {
54
+ queueOptions: zod.ZodType<
55
+ bullmq.QueueOptions,
56
+ zod.ZodTypeDef,
57
+ bullmq.QueueOptions
58
+ >;
59
+ backoffType: zod.ZodUnion<
60
+ [zod.ZodLiteral<'exponential'>, zod.ZodLiteral<'fixed'>]
61
+ >;
62
+ retries: zod.ZodEffects<zod.ZodNumber, number, unknown>;
63
+ interval: zod.ZodEffects<zod.ZodNumber, number, unknown>;
64
+ }
65
+ >;
66
+
67
+ export { BullMqWorkerSchemas };