@boostkit/queue 0.0.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 -0
- package/README.md +49 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +182 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 BoostKit
|
|
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
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @boostkit/queue
|
|
2
|
+
|
|
3
|
+
Queue job abstractions, queue registry, and provider factory with sync and pluggable drivers.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @boostkit/queue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// bootstrap/providers.ts
|
|
15
|
+
import { queue } from '@boostkit/queue'
|
|
16
|
+
import configs from '../config/index.js'
|
|
17
|
+
|
|
18
|
+
export default [
|
|
19
|
+
queue(configs.queue),
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
import { Job } from '@boostkit/queue'
|
|
23
|
+
class SendEmailJob extends Job { async handle() {} }
|
|
24
|
+
await SendEmailJob.dispatch().onQueue('default').send()
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## API Reference
|
|
28
|
+
|
|
29
|
+
- `Job`
|
|
30
|
+
- `DispatchBuilder<T extends Job>`
|
|
31
|
+
- `DispatchOptions`
|
|
32
|
+
- `QueueAdapter`, `QueueAdapterProvider`, `QueueAdapterFactory`
|
|
33
|
+
- `QueueRegistry`
|
|
34
|
+
- `QueueConnectionConfig`, `QueueConfig`
|
|
35
|
+
- `queue(config)`
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
- `QueueConfig`
|
|
40
|
+
- `default`
|
|
41
|
+
- `connections`
|
|
42
|
+
- `QueueConnectionConfig`
|
|
43
|
+
- `driver`
|
|
44
|
+
- additional driver-specific keys
|
|
45
|
+
|
|
46
|
+
## Notes
|
|
47
|
+
|
|
48
|
+
- Built-in driver: `sync`.
|
|
49
|
+
- Plugin drivers supported by factory: `inngest` and `bullmq`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ServiceProvider, type Application } from '@boostkit/core';
|
|
2
|
+
export declare abstract class Job {
|
|
3
|
+
/** The queue this job should be dispatched to */
|
|
4
|
+
static queue: string;
|
|
5
|
+
/** Number of times to retry on failure */
|
|
6
|
+
static retries: number;
|
|
7
|
+
/** Delay before job runs (ms) */
|
|
8
|
+
static delay: number;
|
|
9
|
+
/** The job's main logic */
|
|
10
|
+
abstract handle(): void | Promise<void>;
|
|
11
|
+
/** Called when all retries are exhausted */
|
|
12
|
+
failed?(error: unknown): void | Promise<void>;
|
|
13
|
+
/** Dispatch this job via the global dispatcher */
|
|
14
|
+
static dispatch<T extends Job>(this: new (...args: unknown[]) => T, ...args: ConstructorParameters<typeof this>): DispatchBuilder<T>;
|
|
15
|
+
}
|
|
16
|
+
export declare class DispatchBuilder<T extends Job> {
|
|
17
|
+
private job;
|
|
18
|
+
private _delay;
|
|
19
|
+
private _queue;
|
|
20
|
+
constructor(job: T);
|
|
21
|
+
delay(ms: number): this;
|
|
22
|
+
onQueue(name: string): this;
|
|
23
|
+
send(): Promise<void>;
|
|
24
|
+
then(resolve: () => void): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export interface DispatchOptions {
|
|
27
|
+
delay?: number;
|
|
28
|
+
queue?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface QueueStats {
|
|
31
|
+
waiting: number;
|
|
32
|
+
active: number;
|
|
33
|
+
completed: number;
|
|
34
|
+
failed: number;
|
|
35
|
+
delayed: number;
|
|
36
|
+
paused: number;
|
|
37
|
+
}
|
|
38
|
+
export interface FailedJobInfo {
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
data: unknown;
|
|
42
|
+
error: string;
|
|
43
|
+
failedAt: Date;
|
|
44
|
+
attempts: number;
|
|
45
|
+
}
|
|
46
|
+
export interface QueueAdapter {
|
|
47
|
+
/** Dispatch a job */
|
|
48
|
+
dispatch(job: Job, options?: DispatchOptions): Promise<void>;
|
|
49
|
+
/** Start processing jobs (for self-hosted adapters like BullMQ) — comma-separated queue names */
|
|
50
|
+
work?(queues?: string): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* For cloud adapters (Inngest etc.): returns the serve handler for the
|
|
53
|
+
* /api/inngest endpoint. The QueueServiceProvider mounts it automatically.
|
|
54
|
+
* The returned function receives the framework-native context (Hono Context).
|
|
55
|
+
*/
|
|
56
|
+
serveHandler?(): (ctx: unknown) => Promise<Response>;
|
|
57
|
+
/** Return waiting/active/completed/failed/delayed/paused counts for a queue */
|
|
58
|
+
status?(queueName?: string): Promise<QueueStats>;
|
|
59
|
+
/** Drain waiting + delayed jobs from a queue */
|
|
60
|
+
flush?(queueName?: string): Promise<void>;
|
|
61
|
+
/** List recently failed jobs */
|
|
62
|
+
failures?(queueName?: string, limit?: number): Promise<FailedJobInfo[]>;
|
|
63
|
+
/** Re-enqueue all failed jobs, returns count */
|
|
64
|
+
retryFailed?(queueName?: string): Promise<number>;
|
|
65
|
+
/** Close queue connections */
|
|
66
|
+
disconnect?(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
export interface QueueAdapterProvider {
|
|
69
|
+
create(): QueueAdapter;
|
|
70
|
+
}
|
|
71
|
+
export interface QueueAdapterFactory<TConfig = unknown> {
|
|
72
|
+
(config?: TConfig): QueueAdapterProvider;
|
|
73
|
+
}
|
|
74
|
+
export declare class QueueRegistry {
|
|
75
|
+
private static adapter;
|
|
76
|
+
static set(adapter: QueueAdapter): void;
|
|
77
|
+
static get(): QueueAdapter | null;
|
|
78
|
+
}
|
|
79
|
+
export interface QueueConnectionConfig {
|
|
80
|
+
driver: string;
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
}
|
|
83
|
+
export interface QueueConfig {
|
|
84
|
+
/** The default connection name (e.g. 'sync', 'inngest', 'bullmq') */
|
|
85
|
+
default: string;
|
|
86
|
+
/** Named connections — must have at least one matching `default` */
|
|
87
|
+
connections: Record<string, QueueConnectionConfig>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns a QueueServiceProvider class configured for the given queue config.
|
|
91
|
+
* Reads `config.default` to pick the driver, then boots the matching adapter.
|
|
92
|
+
*
|
|
93
|
+
* Built-in drivers: sync
|
|
94
|
+
* Plugin drivers: inngest (@boostkit/queue-inngest), bullmq (@boostkit/queue-bullmq)
|
|
95
|
+
*
|
|
96
|
+
* Usage in bootstrap/providers.ts:
|
|
97
|
+
* import { queue } from '@boostkit/queue'
|
|
98
|
+
* import configs from '../config/index.js'
|
|
99
|
+
* export default [..., queue(configs.queue), ...]
|
|
100
|
+
*/
|
|
101
|
+
export declare function queue(config: QueueConfig): new (app: Application) => ServiceProvider;
|
|
102
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAW,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAK3E,8BAAsB,GAAG;IACvB,iDAAiD;IACjD,MAAM,CAAC,KAAK,SAAY;IAExB,0CAA0C;IAC1C,MAAM,CAAC,OAAO,SAAI;IAElB,iCAAiC;IACjC,MAAM,CAAC,KAAK,SAAI;IAEhB,2BAA2B;IAC3B,QAAQ,CAAC,MAAM,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAEvC,4CAA4C;IAC5C,MAAM,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAE7C,kDAAkD;IAClD,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,GAAG,EAC3B,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EACnC,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,IAAI,CAAC,GAC1C,eAAe,CAAC,CAAC,CAAC;CAItB;AAID,qBAAa,eAAe,CAAC,CAAC,SAAS,GAAG;IAI5B,OAAO,CAAC,GAAG;IAHvB,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,MAAM,CAAa;gBAEP,GAAG,EAAE,CAAC;IAK1B,KAAK,CAAC,EAAE,EAAE,MAAM,GAA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I,CAAC,CAAA;IAEzC,gCAAgC;IAChC,QAAQ,CAAC,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;IAEvE,gDAAgD;IAChD,WAAW,CAAC,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAEjD,8BAA8B;IAC9B,UAAU,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAID,MAAM,WAAW,oBAAoB;IACnC,MAAM,IAAI,YAAY,CAAA;CACvB;AAED,MAAM,WAAW,mBAAmB,CAAC,OAAO,GAAG,OAAO;IACpD,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,oBAAoB,CAAA;CACzC;AAID,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,OAAO,CAA4B;IAElD,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAIvC,MAAM,CAAC,GAAG,IAAI,YAAY,GAAG,IAAI;CAGlC;AAiBD,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,qEAAqE;IACrE,OAAO,EAAE,MAAM,CAAA;IACf,oEAAoE;IACpE,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAA;CACnD;AAID;;;;;;;;;;;GAWG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,GAAG,EAAE,WAAW,KAAK,eAAe,CA8GpF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { ServiceProvider, artisan } from '@boostkit/core';
|
|
2
|
+
import { resolveOptionalPeer } from '@boostkit/core';
|
|
3
|
+
// ─── Job Contract ──────────────────────────────────────────
|
|
4
|
+
export class Job {
|
|
5
|
+
/** The queue this job should be dispatched to */
|
|
6
|
+
static queue = 'default';
|
|
7
|
+
/** Number of times to retry on failure */
|
|
8
|
+
static retries = 3;
|
|
9
|
+
/** Delay before job runs (ms) */
|
|
10
|
+
static delay = 0;
|
|
11
|
+
/** Dispatch this job via the global dispatcher */
|
|
12
|
+
static dispatch(...args) {
|
|
13
|
+
const instance = new this(...args);
|
|
14
|
+
return new DispatchBuilder(instance);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// ─── Dispatch Builder ──────────────────────────────────────
|
|
18
|
+
export class DispatchBuilder {
|
|
19
|
+
job;
|
|
20
|
+
_delay = 0;
|
|
21
|
+
_queue = 'default';
|
|
22
|
+
constructor(job) {
|
|
23
|
+
this.job = job;
|
|
24
|
+
this._delay = job.constructor.delay;
|
|
25
|
+
this._queue = job.constructor.queue;
|
|
26
|
+
}
|
|
27
|
+
delay(ms) {
|
|
28
|
+
this._delay = ms;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
onQueue(name) {
|
|
32
|
+
this._queue = name;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
async send() {
|
|
36
|
+
const adapter = QueueRegistry.get();
|
|
37
|
+
if (!adapter)
|
|
38
|
+
throw new Error('[BoostKit Queue] No queue adapter registered');
|
|
39
|
+
await adapter.dispatch(this.job, { delay: this._delay, queue: this._queue });
|
|
40
|
+
}
|
|
41
|
+
then(resolve) {
|
|
42
|
+
return this.send().then(resolve);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// ─── Global Queue Registry ─────────────────────────────────
|
|
46
|
+
export class QueueRegistry {
|
|
47
|
+
static adapter = null;
|
|
48
|
+
static set(adapter) {
|
|
49
|
+
this.adapter = adapter;
|
|
50
|
+
}
|
|
51
|
+
static get() {
|
|
52
|
+
return this.adapter;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// ─── Sync Adapter ──────────────────────────────────────────
|
|
56
|
+
class SyncAdapter {
|
|
57
|
+
async dispatch(job) {
|
|
58
|
+
try {
|
|
59
|
+
await job.handle();
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
job.failed?.(error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// ─── Service Provider Factory ──────────────────────────────
|
|
68
|
+
/**
|
|
69
|
+
* Returns a QueueServiceProvider class configured for the given queue config.
|
|
70
|
+
* Reads `config.default` to pick the driver, then boots the matching adapter.
|
|
71
|
+
*
|
|
72
|
+
* Built-in drivers: sync
|
|
73
|
+
* Plugin drivers: inngest (@boostkit/queue-inngest), bullmq (@boostkit/queue-bullmq)
|
|
74
|
+
*
|
|
75
|
+
* Usage in bootstrap/providers.ts:
|
|
76
|
+
* import { queue } from '@boostkit/queue'
|
|
77
|
+
* import configs from '../config/index.js'
|
|
78
|
+
* export default [..., queue(configs.queue), ...]
|
|
79
|
+
*/
|
|
80
|
+
export function queue(config) {
|
|
81
|
+
class QueueServiceProvider extends ServiceProvider {
|
|
82
|
+
register() { }
|
|
83
|
+
async boot() {
|
|
84
|
+
const connectionName = config.default;
|
|
85
|
+
const connectionConfig = config.connections[connectionName] ?? { driver: 'sync' };
|
|
86
|
+
const driver = connectionConfig['driver'];
|
|
87
|
+
let adapter;
|
|
88
|
+
if (driver === 'sync') {
|
|
89
|
+
adapter = new SyncAdapter();
|
|
90
|
+
}
|
|
91
|
+
else if (driver === 'inngest') {
|
|
92
|
+
const { inngest } = await resolveOptionalPeer('@boostkit/queue-inngest');
|
|
93
|
+
adapter = inngest(connectionConfig).create();
|
|
94
|
+
}
|
|
95
|
+
else if (driver === 'bullmq') {
|
|
96
|
+
const { bullmq } = await resolveOptionalPeer('@boostkit/queue-bullmq');
|
|
97
|
+
adapter = bullmq(connectionConfig).create();
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw new Error(`[BoostKit Queue] Unknown driver "${driver}". Available: sync, inngest, bullmq`);
|
|
101
|
+
}
|
|
102
|
+
QueueRegistry.set(adapter);
|
|
103
|
+
this.app.instance('queue', adapter);
|
|
104
|
+
// Always register queue:work so it appears in `pnpm artisan --help`.
|
|
105
|
+
// Fails gracefully when the active driver doesn't support workers (e.g. sync, inngest).
|
|
106
|
+
artisan.command('queue:work', async (args) => {
|
|
107
|
+
if (typeof adapter.work !== 'function') {
|
|
108
|
+
console.error(`[BoostKit Queue] Driver "${driver}" does not support workers.`);
|
|
109
|
+
console.error(`[BoostKit Queue] Switch to "bullmq" in config/queue.ts and set QUEUE_CONNECTION=bullmq in .env.`);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
const queues = args[0] ?? 'default';
|
|
113
|
+
await adapter.work(queues);
|
|
114
|
+
}).description('Start a queue worker — pnpm artisan queue:work [queues=default]');
|
|
115
|
+
artisan.command('queue:status', async (args) => {
|
|
116
|
+
if (typeof adapter.status !== 'function') {
|
|
117
|
+
console.error(`[BoostKit Queue] Driver "${driver}" does not support queue status.`);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
}
|
|
120
|
+
const queueName = args[0] ?? 'default';
|
|
121
|
+
const stats = await adapter.status(queueName);
|
|
122
|
+
console.log(`\nQueue: ${queueName}`);
|
|
123
|
+
console.log(` Waiting: ${stats.waiting}`);
|
|
124
|
+
console.log(` Active: ${stats.active}`);
|
|
125
|
+
console.log(` Completed: ${stats.completed}`);
|
|
126
|
+
console.log(` Failed: ${stats.failed}`);
|
|
127
|
+
console.log(` Delayed: ${stats.delayed}`);
|
|
128
|
+
console.log(` Paused: ${stats.paused}\n`);
|
|
129
|
+
}).description('Show queue stats — pnpm artisan queue:status [queue=default]');
|
|
130
|
+
artisan.command('queue:clear', async (args) => {
|
|
131
|
+
if (typeof adapter.flush !== 'function') {
|
|
132
|
+
console.error(`[BoostKit Queue] Driver "${driver}" does not support queue:clear.`);
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
const queueName = args[0] ?? 'default';
|
|
136
|
+
await adapter.flush(queueName);
|
|
137
|
+
console.log(`[BoostKit Queue] Queue "${queueName}" cleared (waiting + delayed jobs removed).`);
|
|
138
|
+
}).description('Drain waiting + delayed jobs — pnpm artisan queue:clear [queue=default]');
|
|
139
|
+
artisan.command('queue:failed', async (args) => {
|
|
140
|
+
if (typeof adapter.failures !== 'function') {
|
|
141
|
+
console.error(`[BoostKit Queue] Driver "${driver}" does not support queue:failed.`);
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
const queueName = args[0] ?? 'default';
|
|
145
|
+
const jobs = await adapter.failures(queueName);
|
|
146
|
+
if (jobs.length === 0) {
|
|
147
|
+
console.log(`[BoostKit Queue] No failed jobs in queue "${queueName}".`);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
console.log(`\nFailed jobs in queue "${queueName}" (${jobs.length}):\n`);
|
|
151
|
+
for (const job of jobs) {
|
|
152
|
+
console.log(` ID: ${job.id}`);
|
|
153
|
+
console.log(` Name: ${job.name}`);
|
|
154
|
+
console.log(` Error: ${job.error}`);
|
|
155
|
+
console.log(` Attempts: ${job.attempts}`);
|
|
156
|
+
console.log(` Failed: ${job.failedAt.toISOString()}`);
|
|
157
|
+
console.log();
|
|
158
|
+
}
|
|
159
|
+
}).description('List failed jobs — pnpm artisan queue:failed [queue=default]');
|
|
160
|
+
artisan.command('queue:retry', async (args) => {
|
|
161
|
+
if (typeof adapter.retryFailed !== 'function') {
|
|
162
|
+
console.error(`[BoostKit Queue] Driver "${driver}" does not support queue:retry.`);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
const queueName = args[0] ?? 'default';
|
|
166
|
+
const count = await adapter.retryFailed(queueName);
|
|
167
|
+
console.log(`[BoostKit Queue] Re-enqueued ${count} failed job(s) from queue "${queueName}".`);
|
|
168
|
+
}).description('Retry all failed jobs — pnpm artisan queue:retry [queue=default]');
|
|
169
|
+
// Cloud adapters (Inngest etc.) expose a serve endpoint.
|
|
170
|
+
// Mount it automatically — no user config needed.
|
|
171
|
+
if (typeof adapter.serveHandler === 'function') {
|
|
172
|
+
const { router } = await import('@boostkit/router');
|
|
173
|
+
const handler = adapter.serveHandler();
|
|
174
|
+
router.all('/api/inngest', (req) => handler(req.raw));
|
|
175
|
+
console.log(`[QueueServiceProvider] mounted — /api/inngest`);
|
|
176
|
+
}
|
|
177
|
+
console.log(`[QueueServiceProvider] booted — driver: ${driver}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return QueueServiceProvider;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAoB,MAAM,gBAAgB,CAAA;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpD,8DAA8D;AAE9D,MAAM,OAAgB,GAAG;IACvB,iDAAiD;IACjD,MAAM,CAAC,KAAK,GAAG,SAAS,CAAA;IAExB,0CAA0C;IAC1C,MAAM,CAAC,OAAO,GAAG,CAAC,CAAA;IAElB,iCAAiC;IACjC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAA;IAQhB,kDAAkD;IAClD,MAAM,CAAC,QAAQ,CAEb,GAAG,IAAwC;QAE3C,MAAM,QAAQ,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;QAClC,OAAO,IAAI,eAAe,CAAC,QAAQ,CAAC,CAAA;IACtC,CAAC;;AAGH,8DAA8D;AAE9D,MAAM,OAAO,eAAe;IAIN;IAHZ,MAAM,GAAI,CAAC,CAAA;IACX,MAAM,GAAI,SAAS,CAAA;IAE3B,YAAoB,GAAM;QAAN,QAAG,GAAH,GAAG,CAAG;QACxB,IAAI,CAAC,MAAM,GAAI,GAAG,CAAC,WAA0B,CAAC,KAAK,CA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YAAY,KAAK,UAAU,EAAE,CAAC;gBAC/C,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAA;gBACnD,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAA;gBACtC,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;gBACrD,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAA;YAC9D,CAAC;YAED,OAAO,CAAC,GAAG,CAAC,2CAA2C,MAAM,EAAE,CAAC,CAAA;QAClE,CAAC;KACF;IAED,OAAO,oBAAoB,CAAA;AAC7B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@boostkit/queue",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/boostkitjs/boostkit",
|
|
8
|
+
"directory": "packages/queue"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@boostkit/core": "0.0.1",
|
|
24
|
+
"@boostkit/router": "0.0.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "^20.0.0",
|
|
28
|
+
"typescript": "^5.4.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc",
|
|
32
|
+
"dev": "tsc --watch",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"clean": "rm -rf dist"
|
|
35
|
+
}
|
|
36
|
+
}
|