hive-cycle 0.1.0 → 0.1.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.
- package/LICENSE +21 -21
- package/README.md +134 -134
- package/package.json +29 -28
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Jacob K Lewis
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jacob K Lewis
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
# HiveCycle
|
|
4
|
-
|
|
5
|
-
A modular, type-safe TypeScript framework for running background task queues. `HiveCycle` provides a robust backbone for processing queued jobs with concurrency control, automatic retries/requeues, and pluggable queue storage.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- **Continuous Execution**: Runs a worker loop that constantly polls for new tasks.
|
|
10
|
-
- **Type Safe**: leveraging TypeScript generics to strongly type your task payloads.
|
|
11
|
-
- **Modular**: Abstract `QueueAdapter` allowing you to swap the default In-Memory queue for Redis, RabbitMQ, or SQL/NoSQL databases.
|
|
12
|
-
- **Concurrency Control**: Limit how many tasks are processed simultaneously.
|
|
13
|
-
- **Recurring Tasks**: Built-in support for tasks that automatically requeue themselves (cron-like behavior).
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install hive-cycle
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Quick Start
|
|
22
|
-
|
|
23
|
-
### Basic Usage
|
|
24
|
-
|
|
25
|
-
```typescript
|
|
26
|
-
import { HiveCycle } from "hive-cycle";
|
|
27
|
-
|
|
28
|
-
const app = new HiveCycle();
|
|
29
|
-
|
|
30
|
-
// 1. Register a handler
|
|
31
|
-
app.registerHandler("email", async (task) => {
|
|
32
|
-
console.log("Sending email to:", task.payload.to);
|
|
33
|
-
// Perform async work here...
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// 2. Start the engine
|
|
37
|
-
app.start();
|
|
38
|
-
|
|
39
|
-
// 3. Queue a task
|
|
40
|
-
app.enqueue("email", { to: "user@example.com" });
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### Type Safety
|
|
44
|
-
|
|
45
|
-
Define your task map interface to get full autocomplete and type checking for payloads.
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { HiveCycle } from "hive-cycle";
|
|
49
|
-
|
|
50
|
-
// Define your task types and their payloads
|
|
51
|
-
interface MyTaskMap {
|
|
52
|
-
"send-email": { to: string; subject: string; body: string };
|
|
53
|
-
"generate-report": { reportId: string };
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const app = new HiveCycle<MyTaskMap>();
|
|
57
|
-
|
|
58
|
-
// ✅ Fully typed argument
|
|
59
|
-
app.registerHandler("send-email", async (task) => {
|
|
60
|
-
// task.payload is { to: string; subject: string; body: string }
|
|
61
|
-
console.log(task.payload.subject);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// ✅ Type-checked enqueue
|
|
65
|
-
app.enqueue("send-email", {
|
|
66
|
-
to: "test@example.com",
|
|
67
|
-
subject: "Welcome",
|
|
68
|
-
body: "Hello World",
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Advanced Usage
|
|
73
|
-
|
|
74
|
-
### Recurring Tasks
|
|
75
|
-
|
|
76
|
-
You can schedule tasks to automatically requeue themselves after completion, creating a loop.
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
await app.enqueue(
|
|
80
|
-
"cleanup-job",
|
|
81
|
-
{ key: "temp-files" },
|
|
82
|
-
{
|
|
83
|
-
requeue: true,
|
|
84
|
-
requeueDelay: 5000, // Run again 5 seconds after completion
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### Configuration
|
|
90
|
-
|
|
91
|
-
You can pass options to the constructor to tune performance.
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
const app = new HiveCycle({
|
|
95
|
-
// How many tasks to process in parallel
|
|
96
|
-
maxConcurrency: 5,
|
|
97
|
-
|
|
98
|
-
// How often to check for new tasks when queue is empty (ms)
|
|
99
|
-
pollingInterval: 1000,
|
|
100
|
-
|
|
101
|
-
// Custom logger (defaults to console)
|
|
102
|
-
logger: myLogger,
|
|
103
|
-
|
|
104
|
-
// Custom Queue Adapter (defaults to MemoryQueue)
|
|
105
|
-
queue: new RedisQueueAdapter(),
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Custom Queue Adapter
|
|
110
|
-
|
|
111
|
-
To use a persistent store (like Redis), implement the `QueueAdapter` interface.
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
import { QueueAdapter, Task } from "hive-cycle";
|
|
115
|
-
|
|
116
|
-
class MyRedisQueue implements QueueAdapter {
|
|
117
|
-
async enqueue(task: Task): Promise<void> {
|
|
118
|
-
/* ... */
|
|
119
|
-
}
|
|
120
|
-
async dequeue(): Promise<Task | null> {
|
|
121
|
-
/* ... */
|
|
122
|
-
}
|
|
123
|
-
async acknowledge(taskId: string): Promise<void> {
|
|
124
|
-
/* ... */
|
|
125
|
-
}
|
|
126
|
-
async reject(taskId: string, error?: Error): Promise<void> {
|
|
127
|
-
/* ... */
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## License
|
|
133
|
-
|
|
134
|
-
MIT
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# HiveCycle
|
|
4
|
+
|
|
5
|
+
A modular, type-safe TypeScript framework for running background task queues. `HiveCycle` provides a robust backbone for processing queued jobs with concurrency control, automatic retries/requeues, and pluggable queue storage.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Continuous Execution**: Runs a worker loop that constantly polls for new tasks.
|
|
10
|
+
- **Type Safe**: leveraging TypeScript generics to strongly type your task payloads.
|
|
11
|
+
- **Modular**: Abstract `QueueAdapter` allowing you to swap the default In-Memory queue for Redis, RabbitMQ, or SQL/NoSQL databases.
|
|
12
|
+
- **Concurrency Control**: Limit how many tasks are processed simultaneously.
|
|
13
|
+
- **Recurring Tasks**: Built-in support for tasks that automatically requeue themselves (cron-like behavior).
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install hive-cycle
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### Basic Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { HiveCycle } from "hive-cycle";
|
|
27
|
+
|
|
28
|
+
const app = new HiveCycle();
|
|
29
|
+
|
|
30
|
+
// 1. Register a handler
|
|
31
|
+
app.registerHandler("email", async (task) => {
|
|
32
|
+
console.log("Sending email to:", task.payload.to);
|
|
33
|
+
// Perform async work here...
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// 2. Start the engine
|
|
37
|
+
app.start();
|
|
38
|
+
|
|
39
|
+
// 3. Queue a task
|
|
40
|
+
app.enqueue("email", { to: "user@example.com" });
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Type Safety
|
|
44
|
+
|
|
45
|
+
Define your task map interface to get full autocomplete and type checking for payloads.
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { HiveCycle } from "hive-cycle";
|
|
49
|
+
|
|
50
|
+
// Define your task types and their payloads
|
|
51
|
+
interface MyTaskMap {
|
|
52
|
+
"send-email": { to: string; subject: string; body: string };
|
|
53
|
+
"generate-report": { reportId: string };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const app = new HiveCycle<MyTaskMap>();
|
|
57
|
+
|
|
58
|
+
// ✅ Fully typed argument
|
|
59
|
+
app.registerHandler("send-email", async (task) => {
|
|
60
|
+
// task.payload is { to: string; subject: string; body: string }
|
|
61
|
+
console.log(task.payload.subject);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// ✅ Type-checked enqueue
|
|
65
|
+
app.enqueue("send-email", {
|
|
66
|
+
to: "test@example.com",
|
|
67
|
+
subject: "Welcome",
|
|
68
|
+
body: "Hello World",
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Advanced Usage
|
|
73
|
+
|
|
74
|
+
### Recurring Tasks
|
|
75
|
+
|
|
76
|
+
You can schedule tasks to automatically requeue themselves after completion, creating a loop.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
await app.enqueue(
|
|
80
|
+
"cleanup-job",
|
|
81
|
+
{ key: "temp-files" },
|
|
82
|
+
{
|
|
83
|
+
requeue: true,
|
|
84
|
+
requeueDelay: 5000, // Run again 5 seconds after completion
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Configuration
|
|
90
|
+
|
|
91
|
+
You can pass options to the constructor to tune performance.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const app = new HiveCycle({
|
|
95
|
+
// How many tasks to process in parallel
|
|
96
|
+
maxConcurrency: 5,
|
|
97
|
+
|
|
98
|
+
// How often to check for new tasks when queue is empty (ms)
|
|
99
|
+
pollingInterval: 1000,
|
|
100
|
+
|
|
101
|
+
// Custom logger (defaults to console)
|
|
102
|
+
logger: myLogger,
|
|
103
|
+
|
|
104
|
+
// Custom Queue Adapter (defaults to MemoryQueue)
|
|
105
|
+
queue: new RedisQueueAdapter(),
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Custom Queue Adapter
|
|
110
|
+
|
|
111
|
+
To use a persistent store (like Redis), implement the `QueueAdapter` interface.
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { QueueAdapter, Task } from "hive-cycle";
|
|
115
|
+
|
|
116
|
+
class MyRedisQueue implements QueueAdapter {
|
|
117
|
+
async enqueue(task: Task): Promise<void> {
|
|
118
|
+
/* ... */
|
|
119
|
+
}
|
|
120
|
+
async dequeue(): Promise<Task | null> {
|
|
121
|
+
/* ... */
|
|
122
|
+
}
|
|
123
|
+
async acknowledge(taskId: string): Promise<void> {
|
|
124
|
+
/* ... */
|
|
125
|
+
}
|
|
126
|
+
async reject(taskId: string, error?: Error): Promise<void> {
|
|
127
|
+
/* ... */
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "hive-cycle",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "A modular TypeScript framework for background task processing",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist/src",
|
|
9
|
-
"README.md"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "tsc",
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "hive-cycle",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A modular TypeScript framework for background task processing",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/src",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"test": "echo \"No tests specified\" && exit 0",
|
|
14
|
+
"prepublishOnly": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"queue",
|
|
18
|
+
"background-jobs",
|
|
19
|
+
"task-runner",
|
|
20
|
+
"framework",
|
|
21
|
+
"typescript"
|
|
22
|
+
],
|
|
23
|
+
"author": "Jacob K Lewis",
|
|
24
|
+
"repository": "jacobklewis/Hive-Cycle",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"typescript": "^5.0.0",
|
|
28
|
+
"@types/node": "^20.0.0"
|
|
29
|
+
}
|
|
29
30
|
}
|