@boringnode/queue 0.0.1-alpha.3 → 0.1.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 +255 -35
- package/build/chunk-NPQKBCCY.js +26 -0
- package/build/chunk-NPQKBCCY.js.map +1 -0
- package/build/chunk-SMOKFZ46.js +117 -0
- package/build/chunk-SMOKFZ46.js.map +1 -0
- package/build/chunk-US7THLSZ.js +357 -0
- package/build/chunk-US7THLSZ.js.map +1 -0
- package/build/index-2Ng_OpVK.d.ts +1013 -0
- package/build/index.d.ts +429 -4
- package/build/index.js +725 -118
- package/build/index.js.map +1 -1
- package/build/src/contracts/adapter.d.ts +1 -1
- package/build/src/drivers/knex_adapter.d.ts +9 -1
- package/build/src/drivers/knex_adapter.js +253 -42
- package/build/src/drivers/knex_adapter.js.map +1 -1
- package/build/src/drivers/redis_adapter.d.ts +8 -2
- package/build/src/drivers/redis_adapter.js +265 -27
- package/build/src/drivers/redis_adapter.js.map +1 -1
- package/build/src/drivers/sync_adapter.d.ts +13 -3
- package/build/src/drivers/sync_adapter.js +43 -8
- package/build/src/drivers/sync_adapter.js.map +1 -1
- package/build/src/types/index.d.ts +1 -0
- package/build/src/types/index.js +1 -0
- package/build/src/types/index.js.map +1 -0
- package/build/src/types/main.d.ts +1 -1
- package/package.json +16 -3
- package/build/chunk-Y6KR3UIR.js +0 -99
- package/build/chunk-Y6KR3UIR.js.map +0 -1
- package/build/job-Bd_c2lFK.d.ts +0 -149
package/build/chunk-Y6KR3UIR.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
// src/exceptions.ts
|
|
2
|
-
import { createError } from "@poppinss/utils";
|
|
3
|
-
var E_INVALID_DURATION_EXPRESSION = createError(
|
|
4
|
-
'Invalid duration expression: "%s"',
|
|
5
|
-
"E_INVALID_DURATION_EXPRESSION",
|
|
6
|
-
500
|
|
7
|
-
);
|
|
8
|
-
var E_INVALID_BASE_DELAY = createError(
|
|
9
|
-
"Invalid base delay. Reason: %s",
|
|
10
|
-
"E_INVALID_BASE_DELAY",
|
|
11
|
-
500
|
|
12
|
-
);
|
|
13
|
-
var E_INVALID_MAX_DELAY = createError(
|
|
14
|
-
"Invalid max delay. Reason: %s",
|
|
15
|
-
"E_INVALID_MAX_DELAY",
|
|
16
|
-
500
|
|
17
|
-
);
|
|
18
|
-
var E_INVALID_MULTIPLIER = createError(
|
|
19
|
-
"Invalid multiplier. Reason: %s",
|
|
20
|
-
"E_INVALID_MULTIPLIER",
|
|
21
|
-
500
|
|
22
|
-
);
|
|
23
|
-
var E_CONFIGURATION_ERROR = createError(
|
|
24
|
-
"Configuration error. Reason: %s",
|
|
25
|
-
"E_CONFIGURATION_ERROR",
|
|
26
|
-
500
|
|
27
|
-
);
|
|
28
|
-
var E_JOB_NOT_FOUND = createError(
|
|
29
|
-
'Requested job "%s" is not registered',
|
|
30
|
-
"E_JOB_NOT_FOUND"
|
|
31
|
-
);
|
|
32
|
-
var E_JOB_MAX_ATTEMPTS_REACHED = createError(
|
|
33
|
-
'The job "%s" has reached the maximum number of retry attempts',
|
|
34
|
-
"E_JOB_MAX_ATTEMPTS_REACHED"
|
|
35
|
-
);
|
|
36
|
-
var E_JOB_TIMEOUT = createError(
|
|
37
|
-
'The job "%s" has exceeded the timeout of %dms',
|
|
38
|
-
"E_JOB_TIMEOUT"
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
// src/debug.ts
|
|
42
|
-
import { debuglog } from "util";
|
|
43
|
-
var debug_default = debuglog("boringnode:queue");
|
|
44
|
-
|
|
45
|
-
// src/locator.ts
|
|
46
|
-
import { glob } from "fs/promises";
|
|
47
|
-
import { resolve } from "path";
|
|
48
|
-
var LocatorSingleton = class {
|
|
49
|
-
#registry = /* @__PURE__ */ new Map();
|
|
50
|
-
register(name, JobClass) {
|
|
51
|
-
debug_default("registering job: %s", name);
|
|
52
|
-
this.#registry.set(name, JobClass);
|
|
53
|
-
}
|
|
54
|
-
async registerFromGlob(patterns) {
|
|
55
|
-
for (const pattern of patterns) {
|
|
56
|
-
debug_default("registering jobs from glob pattern: %s", pattern);
|
|
57
|
-
for await (const file of glob(pattern)) {
|
|
58
|
-
debug_default("found job file: %s", file);
|
|
59
|
-
try {
|
|
60
|
-
const absolutePath = resolve(file);
|
|
61
|
-
const module = await import(`file://${absolutePath}`);
|
|
62
|
-
const JobClass = module.default;
|
|
63
|
-
if (JobClass && typeof JobClass === "function" && JobClass.name) {
|
|
64
|
-
this.register(JobClass.name, JobClass);
|
|
65
|
-
}
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.warn(`Failed to load job from ${file}:`, error);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
get(name) {
|
|
73
|
-
return this.#registry.get(name);
|
|
74
|
-
}
|
|
75
|
-
getOrThrow(name) {
|
|
76
|
-
const JobClass = this.get(name);
|
|
77
|
-
if (!JobClass) {
|
|
78
|
-
throw new E_JOB_NOT_FOUND([name]);
|
|
79
|
-
}
|
|
80
|
-
return JobClass;
|
|
81
|
-
}
|
|
82
|
-
clear() {
|
|
83
|
-
this.#registry.clear();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
var Locator = new LocatorSingleton();
|
|
87
|
-
|
|
88
|
-
export {
|
|
89
|
-
debug_default,
|
|
90
|
-
E_INVALID_DURATION_EXPRESSION,
|
|
91
|
-
E_INVALID_BASE_DELAY,
|
|
92
|
-
E_INVALID_MAX_DELAY,
|
|
93
|
-
E_INVALID_MULTIPLIER,
|
|
94
|
-
E_CONFIGURATION_ERROR,
|
|
95
|
-
E_JOB_MAX_ATTEMPTS_REACHED,
|
|
96
|
-
E_JOB_TIMEOUT,
|
|
97
|
-
Locator
|
|
98
|
-
};
|
|
99
|
-
//# sourceMappingURL=chunk-Y6KR3UIR.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/exceptions.ts","../src/debug.ts","../src/locator.ts"],"sourcesContent":["import { createError } from '@poppinss/utils'\n\nexport const E_INVALID_DURATION_EXPRESSION = createError(\n 'Invalid duration expression: \"%s\"',\n 'E_INVALID_DURATION_EXPRESSION',\n 500\n)\n\nexport const E_INVALID_BASE_DELAY = createError<[reason: string]>(\n 'Invalid base delay. Reason: %s',\n 'E_INVALID_BASE_DELAY',\n 500\n)\n\nexport const E_INVALID_MAX_DELAY = createError<[reason: string]>(\n 'Invalid max delay. Reason: %s',\n 'E_INVALID_MAX_DELAY',\n 500\n)\n\nexport const E_INVALID_MULTIPLIER = createError<[reason: string]>(\n 'Invalid multiplier. Reason: %s',\n 'E_INVALID_MULTIPLIER',\n 500\n)\n\nexport const E_CONFIGURATION_ERROR = createError<[reason: string]>(\n 'Configuration error. Reason: %s',\n 'E_CONFIGURATION_ERROR',\n 500\n)\n\nexport const E_JOB_NOT_FOUND = createError<[jobName: string]>(\n 'Requested job \"%s\" is not registered',\n 'E_JOB_NOT_FOUND'\n)\n\nexport const E_JOB_MAX_ATTEMPTS_REACHED = createError<[jobName: string]>(\n 'The job \"%s\" has reached the maximum number of retry attempts',\n 'E_JOB_MAX_ATTEMPTS_REACHED'\n)\n\nexport const E_JOB_TIMEOUT = createError<[jobName: string, timeout: number]>(\n 'The job \"%s\" has exceeded the timeout of %dms',\n 'E_JOB_TIMEOUT'\n)\n","import { debuglog } from 'node:util'\n\nexport default debuglog('boringnode:queue')\n","import { Job } from './job.js'\nimport * as errors from './exceptions.js'\nimport type { JobClass } from './types/main.js'\nimport debug from './debug.js'\nimport { glob } from 'node:fs/promises'\nimport { resolve } from 'node:path'\n\nclass LocatorSingleton {\n #registry = new Map<string, JobClass>()\n\n register<T extends Job>(name: string, JobClass: JobClass<T>) {\n debug('registering job: %s', name)\n\n this.#registry.set(name, JobClass)\n }\n\n async registerFromGlob(patterns: string[]) {\n for (const pattern of patterns) {\n debug('registering jobs from glob pattern: %s', pattern)\n for await (const file of glob(pattern)) {\n debug('found job file: %s', file)\n\n try {\n const absolutePath = resolve(file)\n const module = await import(`file://${absolutePath}`)\n const JobClass = module.default as JobClass\n\n if (JobClass && typeof JobClass === 'function' && JobClass.name) {\n this.register(JobClass.name, JobClass)\n }\n } catch (error) {\n console.warn(`Failed to load job from ${file}:`, error)\n }\n }\n }\n }\n\n get<T extends Job = Job>(name: string): JobClass<T> | undefined {\n return this.#registry.get(name) as JobClass<T> | undefined\n }\n\n getOrThrow<T extends Job = Job>(name: string): JobClass<T> {\n const JobClass = this.get<T>(name)\n\n if (!JobClass) {\n throw new errors.E_JOB_NOT_FOUND([name])\n }\n\n return JobClass\n }\n\n clear(): void {\n this.#registry.clear()\n }\n}\n\nexport const Locator = new LocatorSingleton()\n"],"mappings":";AAAA,SAAS,mBAAmB;AAErB,IAAM,gCAAgC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,kBAAkB;AAAA,EAC7B;AAAA,EACA;AACF;AAEO,IAAM,6BAA6B;AAAA,EACxC;AAAA,EACA;AACF;AAEO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AACF;;;AC7CA,SAAS,gBAAgB;AAEzB,IAAO,gBAAQ,SAAS,kBAAkB;;;ACE1C,SAAS,YAAY;AACrB,SAAS,eAAe;AAExB,IAAM,mBAAN,MAAuB;AAAA,EACrB,YAAY,oBAAI,IAAsB;AAAA,EAEtC,SAAwB,MAAc,UAAuB;AAC3D,kBAAM,uBAAuB,IAAI;AAEjC,SAAK,UAAU,IAAI,MAAM,QAAQ;AAAA,EACnC;AAAA,EAEA,MAAM,iBAAiB,UAAoB;AACzC,eAAW,WAAW,UAAU;AAC9B,oBAAM,0CAA0C,OAAO;AACvD,uBAAiB,QAAQ,KAAK,OAAO,GAAG;AACtC,sBAAM,sBAAsB,IAAI;AAEhC,YAAI;AACF,gBAAM,eAAe,QAAQ,IAAI;AACjC,gBAAM,SAAS,MAAM,OAAO,UAAU,YAAY;AAClD,gBAAM,WAAW,OAAO;AAExB,cAAI,YAAY,OAAO,aAAa,cAAc,SAAS,MAAM;AAC/D,iBAAK,SAAS,SAAS,MAAM,QAAQ;AAAA,UACvC;AAAA,QACF,SAAS,OAAO;AACd,kBAAQ,KAAK,2BAA2B,IAAI,KAAK,KAAK;AAAA,QACxD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,IAAyB,MAAuC;AAC9D,WAAO,KAAK,UAAU,IAAI,IAAI;AAAA,EAChC;AAAA,EAEA,WAAgC,MAA2B;AACzD,UAAM,WAAW,KAAK,IAAO,IAAI;AAEjC,QAAI,CAAC,UAAU;AACb,YAAM,IAAW,gBAAgB,CAAC,IAAI,CAAC;AAAA,IACzC;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,QAAc;AACZ,SAAK,UAAU,MAAM;AAAA,EACvB;AACF;AAEO,IAAM,UAAU,IAAI,iBAAiB;","names":[]}
|
package/build/job-Bd_c2lFK.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
declare class BackoffStrategy$1 {
|
|
2
|
-
#private;
|
|
3
|
-
constructor(config: BackoffConfig);
|
|
4
|
-
calculateDelay(attempt: number): number;
|
|
5
|
-
getNextRetryAt(attempt: number): Date;
|
|
6
|
-
getConfig(): Readonly<BackoffConfig>;
|
|
7
|
-
}
|
|
8
|
-
declare function exponentialBackoff(config?: Partial<Omit<BackoffConfig, 'strategy'>>): () => BackoffStrategy$1;
|
|
9
|
-
declare function linearBackoff(config?: Partial<Omit<BackoffConfig, 'strategy'>>): () => BackoffStrategy$1;
|
|
10
|
-
declare function fixedBackoff(delay?: Duration): () => BackoffStrategy$1;
|
|
11
|
-
declare function customBackoff(config: BackoffConfig): () => BackoffStrategy$1;
|
|
12
|
-
|
|
13
|
-
type Duration = number | string;
|
|
14
|
-
interface JobData {
|
|
15
|
-
id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
payload: any;
|
|
18
|
-
attempts: number;
|
|
19
|
-
priority?: number;
|
|
20
|
-
nextRetryAt?: Date;
|
|
21
|
-
}
|
|
22
|
-
interface JobOptions {
|
|
23
|
-
queue?: string;
|
|
24
|
-
adapter?: string | (() => Adapter);
|
|
25
|
-
maxRetries?: number;
|
|
26
|
-
priority?: number;
|
|
27
|
-
retry?: RetryConfig;
|
|
28
|
-
timeout?: Duration;
|
|
29
|
-
failOnTimeout?: boolean;
|
|
30
|
-
}
|
|
31
|
-
type JobClass<T extends Job = Job> = (new (payload: any) => T) & {
|
|
32
|
-
options?: JobOptions;
|
|
33
|
-
};
|
|
34
|
-
interface RetryConfig {
|
|
35
|
-
maxRetries?: number;
|
|
36
|
-
backoff?: () => BackoffStrategy$1;
|
|
37
|
-
}
|
|
38
|
-
type BackoffStrategy = 'exponential' | 'linear' | 'fixed';
|
|
39
|
-
interface BackoffConfig {
|
|
40
|
-
strategy: BackoffStrategy;
|
|
41
|
-
baseDelay: Duration;
|
|
42
|
-
maxDelay?: Duration;
|
|
43
|
-
multiplier?: number;
|
|
44
|
-
jitter?: boolean;
|
|
45
|
-
}
|
|
46
|
-
interface QueueConfig {
|
|
47
|
-
adapter?: string;
|
|
48
|
-
retry?: any;
|
|
49
|
-
}
|
|
50
|
-
interface WorkerConfig {
|
|
51
|
-
concurrency?: number;
|
|
52
|
-
pollingInterval?: Duration;
|
|
53
|
-
leaseTimeout?: Duration;
|
|
54
|
-
renewalInterval?: Duration;
|
|
55
|
-
timeout?: Duration;
|
|
56
|
-
}
|
|
57
|
-
type WorkerCycle = {
|
|
58
|
-
type: 'started';
|
|
59
|
-
queue: string;
|
|
60
|
-
job: any;
|
|
61
|
-
} | {
|
|
62
|
-
type: 'completed';
|
|
63
|
-
queue: string;
|
|
64
|
-
job: any;
|
|
65
|
-
} | {
|
|
66
|
-
type: 'idle';
|
|
67
|
-
suggestedDelay: Duration;
|
|
68
|
-
} | {
|
|
69
|
-
type: 'error';
|
|
70
|
-
error: Error;
|
|
71
|
-
suggestedDelay: Duration;
|
|
72
|
-
};
|
|
73
|
-
type AdapterFactory<T extends Adapter = Adapter> = () => T;
|
|
74
|
-
interface QueueManagerConfig {
|
|
75
|
-
default: string;
|
|
76
|
-
adapters: Record<string, AdapterFactory>;
|
|
77
|
-
retry?: RetryConfig;
|
|
78
|
-
queues?: Record<string, QueueConfig>;
|
|
79
|
-
worker?: WorkerConfig;
|
|
80
|
-
locations: string[];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
interface AcquiredJob extends JobData {
|
|
84
|
-
acquiredAt: number;
|
|
85
|
-
}
|
|
86
|
-
interface Adapter {
|
|
87
|
-
/**
|
|
88
|
-
* Set the worker ID for this adapter instance.
|
|
89
|
-
* Required before calling pop methods when consuming jobs.
|
|
90
|
-
*/
|
|
91
|
-
setWorkerId(workerId: string): void;
|
|
92
|
-
/**
|
|
93
|
-
* Pop the next available job from the default queue.
|
|
94
|
-
* The driver handles locking internally.
|
|
95
|
-
*/
|
|
96
|
-
pop(): Promise<AcquiredJob | null>;
|
|
97
|
-
/**
|
|
98
|
-
* Pop the next available job from a specific queue.
|
|
99
|
-
* The driver handles locking internally.
|
|
100
|
-
*/
|
|
101
|
-
popFrom(queue: string): Promise<AcquiredJob | null>;
|
|
102
|
-
/**
|
|
103
|
-
* Blocking pop that waits for a job to be available.
|
|
104
|
-
* Supported by Redis adapter.
|
|
105
|
-
*/
|
|
106
|
-
popAndWait?(queue: string, timeout: number): Promise<AcquiredJob | null>;
|
|
107
|
-
/**
|
|
108
|
-
* Mark a job as completed and remove it from active set.
|
|
109
|
-
*/
|
|
110
|
-
completeJob(jobId: string, queue: string): Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Mark a job as failed permanently.
|
|
113
|
-
*/
|
|
114
|
-
failJob(jobId: string, queue: string, error?: Error): Promise<void>;
|
|
115
|
-
/**
|
|
116
|
-
* Retry a job - move back to pending queue with incremented attempts.
|
|
117
|
-
*/
|
|
118
|
-
retryJob(jobId: string, queue: string, retryAt?: Date): Promise<void>;
|
|
119
|
-
push(jobData: JobData): Promise<void>;
|
|
120
|
-
pushOn(queue: string, jobData: JobData): Promise<void>;
|
|
121
|
-
pushLater(jobData: JobData, delay: number): Promise<void>;
|
|
122
|
-
pushLaterOn(queue: string, jobData: JobData, delay: number): Promise<void>;
|
|
123
|
-
size(): Promise<number>;
|
|
124
|
-
sizeOf(queue: string): Promise<number>;
|
|
125
|
-
destroy(): Promise<void>;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
declare class JobDispatcher<T> {
|
|
129
|
-
#private;
|
|
130
|
-
constructor(name: string, payload: T);
|
|
131
|
-
toQueue(queue: string): this;
|
|
132
|
-
in(delay: Duration): this;
|
|
133
|
-
priority(priority: number): this;
|
|
134
|
-
with(adapter: string | (() => Adapter)): this;
|
|
135
|
-
run(): Promise<`${string}-${string}-${string}-${string}-${string}`>;
|
|
136
|
-
then(onFulfilled?: (value: string) => any, onRejected?: (reason: any) => any): Promise<any>;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
declare abstract class Job<Payload = any> {
|
|
140
|
-
#private;
|
|
141
|
-
static options: JobOptions;
|
|
142
|
-
get payload(): Payload;
|
|
143
|
-
constructor(payload: Payload);
|
|
144
|
-
static dispatch<T extends Job>(this: new (payload: any) => T, payload: T extends Job<infer P> ? P : never): JobDispatcher<T extends Job<infer P> ? P : never>;
|
|
145
|
-
abstract execute(signal?: AbortSignal): Promise<void>;
|
|
146
|
-
failed?(error: Error): Promise<void>;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export { type Adapter as A, type BackoffStrategy as B, type Duration as D, Job as J, type QueueManagerConfig as Q, type RetryConfig as R, type WorkerCycle as W, type AcquiredJob as a, type JobData as b, customBackoff as c, type JobOptions as d, exponentialBackoff as e, fixedBackoff as f, type JobClass as g, type BackoffConfig as h, type QueueConfig as i, type WorkerConfig as j, type AdapterFactory as k, linearBackoff as l };
|