@queuedash/sdk 0.1.0 → 1.0.0
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 +54 -48
- package/dist/client.d.ts +46 -6
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +316 -46
- package/dist/client.spec.d.ts +2 -0
- package/dist/client.spec.d.ts.map +1 -0
- package/dist/client.spec.js +809 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -8
- package/dist/types.d.ts +10 -3
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -7
- package/dist/integrations/bee.d.ts +0 -8
- package/dist/integrations/bee.d.ts.map +0 -1
- package/dist/integrations/bee.js +0 -43
- package/dist/integrations/bull.d.ts +0 -8
- package/dist/integrations/bull.d.ts.map +0 -1
- package/dist/integrations/bull.js +0 -45
- package/dist/integrations/bullmq.d.ts +0 -8
- package/dist/integrations/bullmq.d.ts.map +0 -1
- package/dist/integrations/bullmq.js +0 -46
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @queuedash/sdk
|
|
2
2
|
|
|
3
|
-
Official SDK for
|
|
3
|
+
Official SDK for Queuedash - Real-time monitoring for BullMQ, Bull, and Bee-Queue.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -14,69 +14,75 @@ yarn add @queuedash/sdk
|
|
|
14
14
|
|
|
15
15
|
## Quick Start
|
|
16
16
|
|
|
17
|
+
The SDK auto-detects your queue library (BullMQ, Bull, or Bee-Queue) - just use `attach()`:
|
|
18
|
+
|
|
17
19
|
### BullMQ
|
|
18
20
|
|
|
19
21
|
```typescript
|
|
20
22
|
import { Queue } from "bullmq";
|
|
21
|
-
import {
|
|
23
|
+
import { Queuedash } from "@queuedash/sdk";
|
|
24
|
+
|
|
25
|
+
const qd = new Queuedash({ apiKey: process.env.QUEUEDASH_API_KEY });
|
|
22
26
|
|
|
23
|
-
// Create your queue
|
|
24
27
|
const myQueue = new Queue("my-queue", {
|
|
25
28
|
connection: { host: "localhost", port: 6379 },
|
|
26
29
|
});
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
const queueDash = new QueueDashClient({
|
|
30
|
-
apiKey: process.env.QUEUEDASH_API_KEY,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// Attach to your queue - that's it!
|
|
34
|
-
attachToBullMQ(myQueue, queueDash);
|
|
31
|
+
qd.attach(myQueue);
|
|
35
32
|
|
|
36
|
-
// Jobs are now automatically synced to
|
|
33
|
+
// Jobs are now automatically synced to Queuedash
|
|
37
34
|
```
|
|
38
35
|
|
|
39
36
|
### Bull
|
|
40
37
|
|
|
41
38
|
```typescript
|
|
42
39
|
import Queue from "bull";
|
|
43
|
-
import {
|
|
40
|
+
import { Queuedash } from "@queuedash/sdk";
|
|
44
41
|
|
|
45
|
-
const
|
|
46
|
-
redis: { host: "localhost", port: 6379 },
|
|
47
|
-
});
|
|
42
|
+
const qd = new Queuedash({ apiKey: process.env.QUEUEDASH_API_KEY });
|
|
48
43
|
|
|
49
|
-
const
|
|
50
|
-
apiKey: process.env.QUEUEDASH_API_KEY,
|
|
51
|
-
});
|
|
44
|
+
const myQueue = new Queue("my-queue", "redis://localhost:6379");
|
|
52
45
|
|
|
53
|
-
|
|
46
|
+
qd.attach(myQueue);
|
|
54
47
|
```
|
|
55
48
|
|
|
56
49
|
### Bee-Queue
|
|
57
50
|
|
|
58
51
|
```typescript
|
|
59
52
|
import Queue from "bee-queue";
|
|
60
|
-
import {
|
|
53
|
+
import { Queuedash } from "@queuedash/sdk";
|
|
54
|
+
|
|
55
|
+
const qd = new Queuedash({ apiKey: process.env.QUEUEDASH_API_KEY });
|
|
61
56
|
|
|
62
57
|
const myQueue = new Queue("my-queue", {
|
|
63
58
|
redis: { host: "localhost", port: 6379 },
|
|
64
59
|
});
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
61
|
+
qd.attach(myQueue);
|
|
62
|
+
```
|
|
69
63
|
|
|
70
|
-
|
|
64
|
+
### Multiple Queues
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { Queue } from "bullmq";
|
|
68
|
+
import { Queuedash } from "@queuedash/sdk";
|
|
69
|
+
|
|
70
|
+
const qd = new Queuedash({ apiKey: process.env.QUEUEDASH_API_KEY });
|
|
71
|
+
|
|
72
|
+
const connection = { host: "localhost", port: 6379 };
|
|
73
|
+
|
|
74
|
+
qd.attach(new Queue("emails", { connection }));
|
|
75
|
+
qd.attach(new Queue("reports", { connection }));
|
|
76
|
+
qd.attach(new Queue("notifications", { connection }));
|
|
71
77
|
```
|
|
72
78
|
|
|
73
79
|
## Configuration
|
|
74
80
|
|
|
75
81
|
### API Key
|
|
76
82
|
|
|
77
|
-
Get your API key from [
|
|
83
|
+
Get your API key from [Queuedash](https://queuedash.com):
|
|
78
84
|
|
|
79
|
-
1. Navigate to your
|
|
85
|
+
1. Navigate to your project
|
|
80
86
|
2. Click "API Keys"
|
|
81
87
|
3. Generate a new API key
|
|
82
88
|
|
|
@@ -85,34 +91,37 @@ Get your API key from [QueueDash](https://queuedash.com):
|
|
|
85
91
|
QUEUEDASH_API_KEY=sk_live_...
|
|
86
92
|
```
|
|
87
93
|
|
|
88
|
-
###
|
|
94
|
+
### Options
|
|
89
95
|
|
|
90
96
|
```typescript
|
|
91
|
-
|
|
92
|
-
// Required: Your API key from
|
|
93
|
-
apiKey: string
|
|
97
|
+
const qd = new Queuedash({
|
|
98
|
+
// Required: Your API key from Queuedash
|
|
99
|
+
apiKey: string,
|
|
100
|
+
|
|
101
|
+
// Optional: Custom API URL (default: https://api.queuedash.com)
|
|
102
|
+
baseUrl?: string,
|
|
94
103
|
|
|
95
|
-
// Optional: Batch size for syncing jobs (
|
|
96
|
-
batchSize?: number
|
|
104
|
+
// Optional: Batch size for syncing jobs (default: 50)
|
|
105
|
+
batchSize?: number,
|
|
97
106
|
|
|
98
|
-
// Optional: Flush interval in milliseconds (
|
|
99
|
-
flushInterval?: number
|
|
107
|
+
// Optional: Flush interval in milliseconds (default: 100)
|
|
108
|
+
flushInterval?: number,
|
|
100
109
|
|
|
101
|
-
// Optional: Max retry attempts with exponential backoff (
|
|
102
|
-
maxRetries?: number
|
|
110
|
+
// Optional: Max retry attempts with exponential backoff (default: 5)
|
|
111
|
+
maxRetries?: number,
|
|
103
112
|
|
|
104
|
-
// Optional: Request timeout in milliseconds (
|
|
105
|
-
requestTimeout?: number
|
|
113
|
+
// Optional: Request timeout in milliseconds (default: 30000)
|
|
114
|
+
requestTimeout?: number,
|
|
106
115
|
|
|
107
|
-
// Optional: Max jobs to queue in memory (
|
|
108
|
-
maxQueueSize?: number
|
|
116
|
+
// Optional: Max jobs to queue in memory (default: 10000)
|
|
117
|
+
maxQueueSize?: number,
|
|
109
118
|
|
|
110
119
|
// Optional: Error handler called on critical failures
|
|
111
|
-
onError?: (error: Error) => void
|
|
112
|
-
}
|
|
120
|
+
onError?: (error: Error) => void,
|
|
121
|
+
});
|
|
113
122
|
```
|
|
114
123
|
|
|
115
|
-
|
|
124
|
+
## Reliability & Robustness
|
|
116
125
|
|
|
117
126
|
The SDK is production-ready with multiple layers of protection:
|
|
118
127
|
|
|
@@ -137,7 +146,7 @@ The SDK is production-ready with multiple layers of protection:
|
|
|
137
146
|
**Graceful Shutdown**
|
|
138
147
|
|
|
139
148
|
- SIGTERM/SIGINT handlers flush pending jobs before exit
|
|
140
|
-
-
|
|
149
|
+
- Call `await qd.stop()` to manually stop
|
|
141
150
|
- No jobs lost during normal shutdown
|
|
142
151
|
|
|
143
152
|
**Request Safety**
|
|
@@ -148,16 +157,13 @@ The SDK is production-ready with multiple layers of protection:
|
|
|
148
157
|
|
|
149
158
|
## Features
|
|
150
159
|
|
|
160
|
+
- **Auto-detection**: Works with BullMQ, Bull, and Bee-Queue automatically
|
|
151
161
|
- **Real-time sync**: Jobs are synced as events happen
|
|
152
162
|
- **Smart batching**: Events are automatically batched for performance
|
|
153
163
|
- **Auto-retry**: Failed syncs are automatically retried
|
|
154
164
|
- **Zero config**: Works out of the box with sensible defaults
|
|
155
165
|
- **TypeScript**: Full TypeScript support
|
|
156
166
|
|
|
157
|
-
## How It Works
|
|
158
|
-
|
|
159
|
-
The SDK automatically syncs your queue jobs to QueueDash's SaaS platform at `api.queuedash.com`. Just provide your API key and you're done - no additional configuration needed!
|
|
160
|
-
|
|
161
167
|
## License
|
|
162
168
|
|
|
163
169
|
MIT
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { JobData,
|
|
2
|
-
|
|
1
|
+
import { JobData, QueuedashOptions } from "./types";
|
|
2
|
+
type BullMQQueueEvents = {
|
|
3
|
+
on: (event: string, handler: (...args: any[]) => void) => any;
|
|
4
|
+
close: () => Promise<void>;
|
|
5
|
+
};
|
|
6
|
+
export declare class Queuedash {
|
|
3
7
|
private apiKey;
|
|
4
8
|
private apiUrl;
|
|
5
9
|
private batchSize;
|
|
@@ -16,9 +20,44 @@ export declare class QueueDashClient {
|
|
|
16
20
|
private circuitBreakerOpen;
|
|
17
21
|
private circuitBreakerResetTimer?;
|
|
18
22
|
private syncingJobIds;
|
|
19
|
-
|
|
23
|
+
private managedQueueEvents;
|
|
24
|
+
private attachedQueues;
|
|
25
|
+
constructor(options: QueuedashOptions);
|
|
20
26
|
/**
|
|
21
|
-
*
|
|
27
|
+
* Attach a queue or worker for monitoring.
|
|
28
|
+
* Auto-detects the queue library (BullMQ, Bull, Bee-Queue).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const qd = new Queuedash({ apiKey: 'qd_...' });
|
|
33
|
+
*
|
|
34
|
+
* // BullMQ - we create QueueEvents internally
|
|
35
|
+
* qd.attach(myBullMQQueue);
|
|
36
|
+
*
|
|
37
|
+
* // Bull
|
|
38
|
+
* qd.attach(myBullQueue);
|
|
39
|
+
*
|
|
40
|
+
* // Bee-Queue
|
|
41
|
+
* qd.attach(myBeeQueue);
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
attach(resource: unknown, options?: {
|
|
45
|
+
events?: BullMQQueueEvents;
|
|
46
|
+
}): this;
|
|
47
|
+
private detectType;
|
|
48
|
+
private attachBullMQ;
|
|
49
|
+
private attachBullMQWorker;
|
|
50
|
+
private attachBull;
|
|
51
|
+
private attachBee;
|
|
52
|
+
private extractBullMQJobData;
|
|
53
|
+
private extractBullJobData;
|
|
54
|
+
private extractBeeJobData;
|
|
55
|
+
/**
|
|
56
|
+
* Delete a job (soft delete in Queuedash)
|
|
57
|
+
*/
|
|
58
|
+
deleteJob(jobId: string, queueName: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Queue a job for syncing (internal use)
|
|
22
61
|
*/
|
|
23
62
|
syncJob(job: JobData): void;
|
|
24
63
|
/**
|
|
@@ -26,12 +65,13 @@ export declare class QueueDashClient {
|
|
|
26
65
|
*/
|
|
27
66
|
flush(): Promise<void>;
|
|
28
67
|
private openCircuitBreaker;
|
|
29
|
-
private
|
|
68
|
+
private log;
|
|
30
69
|
/**
|
|
31
|
-
* Stop the client and flush remaining jobs
|
|
70
|
+
* Stop the client, close managed resources, and flush remaining jobs
|
|
32
71
|
*/
|
|
33
72
|
stop(): Promise<void>;
|
|
34
73
|
private startFlushTimer;
|
|
35
74
|
private setupShutdownHandlers;
|
|
36
75
|
}
|
|
76
|
+
export {};
|
|
37
77
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAgB,MAAM,SAAS,CAAC;AAelE,KAAK,iBA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