hive-cycle 0.2.0 → 0.2.2

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.
package/README.md CHANGED
@@ -11,6 +11,7 @@ A modular, type-safe TypeScript framework for running background task queues. `H
11
11
  - **Modular**: Abstract `QueueAdapter` allowing you to swap the default In-Memory queue for Redis, RabbitMQ, or SQL/NoSQL databases.
12
12
  - **Concurrency Control**: Limit how many tasks are processed simultaneously.
13
13
  - **Recurring Tasks**: Built-in support for tasks that automatically requeue themselves (cron-like behavior).
14
+ - **Health Monitoring**: Optional HTTP endpoint to monitor service health and metrics.
14
15
 
15
16
  ## Installation
16
17
 
@@ -82,7 +83,7 @@ await app.enqueue(
82
83
  {
83
84
  requeue: true,
84
85
  requeueDelay: 5000, // Run again 5 seconds after completion
85
- }
86
+ },
86
87
  );
87
88
  ```
88
89
 
@@ -101,11 +102,32 @@ const app = new HiveCycle({
101
102
  // Custom logger (defaults to console)
102
103
  logger: myLogger,
103
104
 
105
+ // Start a health check server on this port
106
+ healthPort: 3000,
107
+
104
108
  // Custom Queue Adapter (defaults to MemoryQueue)
105
109
  queue: new RedisQueueAdapter(),
106
110
  });
107
111
  ```
108
112
 
113
+ ### Health Check
114
+
115
+ If you provide a `healthPort` in the configuration, an HTTP server will start and expose a `/health` endpoint.
116
+
117
+ ```bash
118
+ curl http://localhost:3000/health
119
+ ```
120
+
121
+ **Response:**
122
+
123
+ ```json
124
+ {
125
+ "status": "ok",
126
+ "running": true,
127
+ "activeCount": 2
128
+ }
129
+ ```
130
+
109
131
  ### Custom Queue Adapter
110
132
 
111
133
  To use a persistent store (like Redis), implement the `QueueAdapter` interface.
@@ -29,3 +29,4 @@ export declare class HiveCycle<TaskMap extends Record<string, any> = Record<stri
29
29
  private handleTask;
30
30
  private sleep;
31
31
  }
32
+ //# sourceMappingURL=HiveCycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HiveCycle.d.ts","sourceRoot":"","sources":["../src/HiveCycle.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAEhB,IAAI,EACJ,WAAW,EAEZ,MAAM,SAAS,CAAC;AAcjB,qBAAa,SAAS,CACpB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAEzD,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,QAAQ,CAAuC;IACvD,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,OAAO,CAEb;IACF,OAAO,CAAC,WAAW,CAAa;IAChC,OAAO,CAAC,MAAM,CAAC,CAAS;gBAEZ,OAAO,GAAE,gBAAqB;IAW1C;;OAEG;IACI,eAAe,CAAC,CAAC,SAAS,MAAM,OAAO,GAAG,MAAM,EACrD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAC/B,IAAI;IAIP;;OAEG;IACU,OAAO,CAAC,CAAC,SAAS,MAAM,OAAO,GAAG,MAAM,EACnD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GACtB,OAAO,CAAC,MAAM,CAAC;IAYlB;;OAEG;IACI,KAAK,IAAI,IAAI;IAYpB;;OAEG;IACI,IAAI,IAAI,IAAI;IAMnB,OAAO,CAAC,iBAAiB;IA0BzB,OAAO,CAAC,gBAAgB;YAOV,IAAI;YA0BJ,UAAU;IAyCxB,OAAO,CAAC,KAAK;CAGd"}
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HiveCycle = void 0;
4
- const http_1 = require("http");
5
- const MemoryQueue_1 = require("./MemoryQueue");
1
+ import { createServer } from "http";
2
+ import { MemoryQueue } from "./MemoryQueue";
6
3
  // I will implement a simple ID generator to avoid deps for now if I didn't install uuid.
7
4
  // Wait, I haven't installed `uuid`. I should probably implement a simple random ID or install it later.
8
5
  // User didn't ask for uuid specifically, so I'll use crypto.randomUUID if available or Math.random shim.
@@ -12,13 +9,13 @@ function generateId() {
12
9
  }
13
10
  return Math.random().toString(36).substring(2, 15);
14
11
  }
15
- class HiveCycle {
12
+ export class HiveCycle {
16
13
  constructor(options = {}) {
17
14
  this.handlers = new Map();
18
15
  this.isRunning = false;
19
16
  this.activeCount = 0;
20
17
  this.options = {
21
- queue: options.queue || new MemoryQueue_1.MemoryQueue(),
18
+ queue: options.queue || new MemoryQueue(),
22
19
  pollingInterval: options.pollingInterval || 1000,
23
20
  maxConcurrency: options.maxConcurrency || 1,
24
21
  logger: options.logger || console,
@@ -68,7 +65,7 @@ class HiveCycle {
68
65
  this.stopHealthServer();
69
66
  }
70
67
  startHealthServer(port) {
71
- this.server = (0, http_1.createServer)((req, res) => {
68
+ this.server = createServer((req, res) => {
72
69
  if (req.url === "/health" && req.method === "GET") {
73
70
  res.writeHead(200, { "Content-Type": "application/json" });
74
71
  res.end(JSON.stringify({
@@ -165,4 +162,3 @@ class HiveCycle {
165
162
  return new Promise((resolve) => setTimeout(resolve, ms));
166
163
  }
167
164
  }
168
- exports.HiveCycle = HiveCycle;
@@ -7,3 +7,4 @@ export declare class MemoryQueue implements QueueAdapter {
7
7
  acknowledge(taskId: string): Promise<void>;
8
8
  reject(taskId: string, error?: Error): Promise<void>;
9
9
  }
10
+ //# sourceMappingURL=MemoryQueue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MemoryQueue.d.ts","sourceRoot":"","sources":["../src/MemoryQueue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE7C,qBAAa,WAAY,YAAW,YAAY;IAC9C,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,UAAU,CAAgC;IAE5C,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,OAAO,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAQ/B,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAQ3D"}
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryQueue = void 0;
4
- class MemoryQueue {
1
+ export class MemoryQueue {
5
2
  constructor() {
6
3
  this.queue = [];
7
4
  this.processing = new Map();
@@ -28,4 +25,3 @@ class MemoryQueue {
28
25
  }
29
26
  }
30
27
  }
31
- exports.MemoryQueue = MemoryQueue;
@@ -0,0 +1,4 @@
1
+ export * from "./types";
2
+ export * from "./HiveCycle";
3
+ export * from "./MemoryQueue";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
@@ -44,3 +44,4 @@ export interface Logger {
44
44
  error(message: string, ...args: any[]): void;
45
45
  warn(message: string, ...args: any[]): void;
46
46
  }
47
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI,CAAC,CAAC,GAAG,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEnC;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAEhC;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3C;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,MAAM;IACrB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC3C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAC7C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CAC7C"}
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "hive-cycle",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "A modular TypeScript framework for background task processing",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
- "dist/src",
9
- "README.md"
8
+ "dist",
9
+ "README.md",
10
+ "LICENSE"
10
11
  ],
11
12
  "scripts": {
12
13
  "build": "tsc",
package/dist/src/index.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./HiveCycle"), exports);
19
- __exportStar(require("./MemoryQueue"), exports);
package/dist/src/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
File without changes