@stacksjs/bun-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/CHANGELOG.md +79 -0
- package/LICENSE.md +21 -0
- package/README.md +231 -0
- package/dist/batch.d.ts +18 -0
- package/dist/bin/cli.js +1914 -0
- package/dist/cleanup.d.ts +22 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/script-loader.d.ts +44 -0
- package/dist/config.d.ts +4 -0
- package/dist/cron-scheduler.d.ts +37 -0
- package/dist/dead-letter-queue.d.ts +16 -0
- package/dist/dispatch.d.ts +84 -0
- package/dist/distributed-lock.d.ts +25 -0
- package/dist/events.d.ts +27 -0
- package/dist/failed/failed-job-manager.d.ts +17 -0
- package/dist/failed/failed-job-provider.d.ts +37 -0
- package/dist/failed/index.d.ts +7 -0
- package/dist/group.d.ts +22 -0
- package/dist/index.d.ts +72 -0
- package/dist/job-base.d.ts +95 -0
- package/dist/job-processor.d.ts +21 -0
- package/dist/job.d.ts +27 -0
- package/dist/jobs/bus.d.ts +60 -0
- package/dist/jobs/index.d.ts +14 -0
- package/dist/jobs/middleware.d.ts +37 -0
- package/dist/leader-election.d.ts +39 -0
- package/dist/logger.d.ts +14 -0
- package/dist/metrics.d.ts +22 -0
- package/dist/middleware.d.ts +61 -0
- package/dist/observable.d.ts +23 -0
- package/dist/priority-queue.d.ts +40 -0
- package/dist/queue-manager.d.ts +24 -0
- package/dist/queue.d.ts +114 -0
- package/dist/rate-limiter.d.ts +13 -0
- package/dist/src/index.js +17057 -0
- package/dist/stalled-checker.d.ts +14 -0
- package/dist/types.d.ts +180 -0
- package/dist/utils.d.ts +26 -0
- package/dist/work-coordinator.d.ts +35 -0
- package/dist/worker.d.ts +19 -0
- package/dist/workers/index.d.ts +6 -0
- package/dist/workers/queue-worker.d.ts +62 -0
- package/dist/workers/worker-manager.d.ts +22 -0
- package/package.json +75 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Queue } from './queue';
|
|
2
|
+
declare interface CleanupOptions {
|
|
3
|
+
maxCompletedJobs?: number
|
|
4
|
+
maxFailedJobs?: number
|
|
5
|
+
completedJobsLifetime?: number
|
|
6
|
+
failedJobsLifetime?: number
|
|
7
|
+
cleanupInterval?: number
|
|
8
|
+
}
|
|
9
|
+
declare class CleanupService {
|
|
10
|
+
readonly private queue: Queue;
|
|
11
|
+
readonly private logger: any;
|
|
12
|
+
readonly private options: CleanupOptions;
|
|
13
|
+
private timer: NodeJS.Timeout | null;
|
|
14
|
+
private running: any;
|
|
15
|
+
constructor(queue: Queue, options?: CleanupOptions);
|
|
16
|
+
start(): void;
|
|
17
|
+
stop(): void;
|
|
18
|
+
private cleanup(): Promise<void>;
|
|
19
|
+
private cleanupCompletedJobs(): Promise<void>;
|
|
20
|
+
private cleanupFailedJobs(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export { type CleanupOptions, CleanupService };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { RedisClient } from '../types';
|
|
2
|
+
export declare interface Command {
|
|
3
|
+
name: string
|
|
4
|
+
options: {
|
|
5
|
+
numberOfKeys: number
|
|
6
|
+
lua: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Script metadata
|
|
11
|
+
*/
|
|
12
|
+
export declare interface ScriptMetadata {
|
|
13
|
+
name: string
|
|
14
|
+
numberOfKeys?: number
|
|
15
|
+
path: string
|
|
16
|
+
content: string
|
|
17
|
+
token: string
|
|
18
|
+
includes: ScriptMetadata[]
|
|
19
|
+
}
|
|
20
|
+
export declare class ScriptLoaderError extends Error {
|
|
21
|
+
readonly includes: string[];
|
|
22
|
+
readonly line: number;
|
|
23
|
+
readonly position: number;
|
|
24
|
+
constructor(message: string, path: string, stack?: string[], line?: number, position?: any);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Lua script loader with include support
|
|
28
|
+
*/
|
|
29
|
+
export declare class ScriptLoader {
|
|
30
|
+
private pathMapper: any;
|
|
31
|
+
private clientScripts: any;
|
|
32
|
+
private commandCache: any;
|
|
33
|
+
private rootPath: string;
|
|
34
|
+
constructor();
|
|
35
|
+
addPathMapping(name: string, mappedPath: string): void;
|
|
36
|
+
resolvePath(scriptName: string, stack?: string[]): string;
|
|
37
|
+
private resolveDependencies(file: ScriptMetadata, cache?: Map<string, ScriptMetadata>, isInclude?: any, stack?: string[]): Promise<void>;
|
|
38
|
+
parseScript(filename: string, content: string, cache?: Map<string, ScriptMetadata>): Promise<ScriptMetadata>;
|
|
39
|
+
interpolate(file: ScriptMetadata, processed?: Set<string>): string;
|
|
40
|
+
loadCommand(filename: string, cache?: Map<string, ScriptMetadata>): Promise<Command>;
|
|
41
|
+
loadScripts(dir?: string, cache?: Map<string, ScriptMetadata>): Promise<Command[]>;
|
|
42
|
+
load(client: RedisClient, pathname: string, cache?: Map<string, ScriptMetadata>): Promise<void>;
|
|
43
|
+
clearCache(): void;
|
|
44
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { JobOptions } from './types';
|
|
2
|
+
import type { Queue } from './queue';
|
|
3
|
+
/**
|
|
4
|
+
* CronSchedule represents the parsed cron expression
|
|
5
|
+
*/
|
|
6
|
+
declare interface CronSchedule {
|
|
7
|
+
minute: number[] | null
|
|
8
|
+
hour: number[] | null
|
|
9
|
+
dayOfMonth: number[] | null
|
|
10
|
+
month: number[] | null
|
|
11
|
+
dayOfWeek: number[] | null
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Options for a cron job
|
|
15
|
+
*/
|
|
16
|
+
export declare interface CronJobOptions extends Omit<JobOptions, 'repeat'> {
|
|
17
|
+
cronExpression: string
|
|
18
|
+
timezone?: string
|
|
19
|
+
data: any
|
|
20
|
+
startDate?: Date | number
|
|
21
|
+
endDate?: Date | number
|
|
22
|
+
limit?: number
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Class that handles scheduling jobs based on cron expressions
|
|
26
|
+
*/
|
|
27
|
+
export declare class CronScheduler {
|
|
28
|
+
readonly private queue: Queue;
|
|
29
|
+
readonly private logger: any;
|
|
30
|
+
private scheduledJobs: Map<string, NodeJS.Timeout>;
|
|
31
|
+
constructor(queue: Queue);
|
|
32
|
+
schedule(options: CronJobOptions): Promise<string>;
|
|
33
|
+
private parseCronExpression(expression: string): CronSchedule;
|
|
34
|
+
private parseField(field: string, min: number, max: number): number[] | null;
|
|
35
|
+
private getNextExecutionTime(schedule: CronSchedule, now: Date, timezone?: string): Date | null;
|
|
36
|
+
unschedule(jobId: string): Promise<boolean>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Job } from './job';
|
|
2
|
+
import type { DeadLetterQueueOptions } from './types';
|
|
3
|
+
import type { Queue } from './queue';
|
|
4
|
+
export declare class DeadLetterQueue<T = any> {
|
|
5
|
+
private queue: Queue<T>;
|
|
6
|
+
private deadLetterQueueName: string;
|
|
7
|
+
private options: DeadLetterQueueOptions;
|
|
8
|
+
private logger: any;
|
|
9
|
+
constructor(queue: Queue<T>, options?: DeadLetterQueueOptions);
|
|
10
|
+
getQueueName(): string;
|
|
11
|
+
moveToDeadLetter(job: Job<T>, reason: string): Promise<string>;
|
|
12
|
+
getJobs(start?: any, end?: any): Promise<Job<T>[]>;
|
|
13
|
+
republishJob(jobId: string, options?: { resetRetries?: boolean }): Promise<Job<T> | null>;
|
|
14
|
+
removeJob(jobId: string): Promise<boolean>;
|
|
15
|
+
clear(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Job } from './job';
|
|
2
|
+
import type { JobContract } from './job-base';
|
|
3
|
+
export declare function dispatch<T extends JobContract>(job: T, ...args: any[]): Promise<Job<any>>;
|
|
4
|
+
export declare function dispatchSync<T extends JobContract>(job: T, ...args: any[]): Promise<any>;
|
|
5
|
+
export declare function dispatchIf<T extends JobContract>(condition: boolean, job: T, ...args: any[]): Promise<Job<any> | null>;
|
|
6
|
+
export declare function dispatchUnless<T extends JobContract>(condition: boolean, job: T, ...args: any[]): Promise<Job<any> | null>;
|
|
7
|
+
export declare function dispatchAfter<T extends JobContract>(delay: number, job: T, ...args: any[]): Promise<Job<any>>;
|
|
8
|
+
export declare function chain<T extends JobContract>(job: T, ...args: any[]): DispatchableChain;
|
|
9
|
+
export declare function batch(name?: string): JobBatch;
|
|
10
|
+
export declare function dispatchChain(jobs: JobContract[]): Promise<Job<any>[]>;
|
|
11
|
+
export declare function dispatchFunction(fn: QueuedClosure, ...args: any[]): Promise<Job<any>>;
|
|
12
|
+
export declare interface DispatchChain {
|
|
13
|
+
onQueue: (queue: string) => this
|
|
14
|
+
onConnection: (connection: string) => this
|
|
15
|
+
delay: (ms: number) => this
|
|
16
|
+
after: (delay: number) => this
|
|
17
|
+
withTries: (attempts: number) => this
|
|
18
|
+
withTimeout: (timeout: number) => this
|
|
19
|
+
withBackoff: (backoff: number[]) => this
|
|
20
|
+
withTags: (...tags: string[]) => this
|
|
21
|
+
dispatch: () => Promise<Job<any>>
|
|
22
|
+
dispatchSync: () => Promise<any>
|
|
23
|
+
}
|
|
24
|
+
export declare interface Batch {
|
|
25
|
+
id: string
|
|
26
|
+
name?: string
|
|
27
|
+
jobs: JobContract[]
|
|
28
|
+
options?: BatchOptions
|
|
29
|
+
dispatch: () => Promise<BatchResult>
|
|
30
|
+
}
|
|
31
|
+
export declare interface BatchOptions {
|
|
32
|
+
allowFailures?: boolean
|
|
33
|
+
concurrency?: number
|
|
34
|
+
timeout?: number
|
|
35
|
+
onQueue?: string
|
|
36
|
+
onConnection?: string
|
|
37
|
+
}
|
|
38
|
+
export declare interface BatchResult {
|
|
39
|
+
id: string
|
|
40
|
+
jobs: Job<any>[]
|
|
41
|
+
completed: number
|
|
42
|
+
failed: number
|
|
43
|
+
total: number
|
|
44
|
+
}
|
|
45
|
+
export declare interface QueuedClosure {
|
|
46
|
+
(...args: any[]): Promise<any> | any
|
|
47
|
+
}
|
|
48
|
+
export declare class DispatchableChain implements DispatchChain {
|
|
49
|
+
private jobInstance: JobContract;
|
|
50
|
+
private args: any[];
|
|
51
|
+
private queueName?: string;
|
|
52
|
+
private connectionName?: string;
|
|
53
|
+
private delayMs?: number;
|
|
54
|
+
private attempts?: number;
|
|
55
|
+
private timeoutMs?: number;
|
|
56
|
+
private backoffArray?: number[];
|
|
57
|
+
private jobTags?: string[];
|
|
58
|
+
constructor(job: JobContract, args: any[]);
|
|
59
|
+
onQueue(queue: string): this;
|
|
60
|
+
onConnection(connection: string): this;
|
|
61
|
+
delay(ms: number): this;
|
|
62
|
+
after(delay: number): this;
|
|
63
|
+
withTries(attempts: number): this;
|
|
64
|
+
withTimeout(timeout: number): this;
|
|
65
|
+
withBackoff(backoff: number[]): this;
|
|
66
|
+
withTags(tags: string[]): this;
|
|
67
|
+
dispatch(): Promise<Job<any>>;
|
|
68
|
+
dispatchSync(): Promise<any>;
|
|
69
|
+
}
|
|
70
|
+
export declare class JobBatch implements Batch {
|
|
71
|
+
id: string;
|
|
72
|
+
name?: string;
|
|
73
|
+
jobs: JobContract[];
|
|
74
|
+
options?: BatchOptions;
|
|
75
|
+
constructor(name?: string);
|
|
76
|
+
add(job: JobContract): this;
|
|
77
|
+
addMany(jobs: JobContract[]): this;
|
|
78
|
+
allowFailures(allow?: any): this;
|
|
79
|
+
withConcurrency(concurrency: number): this;
|
|
80
|
+
withTimeout(timeout: number): this;
|
|
81
|
+
onQueue(queue: string): this;
|
|
82
|
+
onConnection(connection: string): this;
|
|
83
|
+
dispatch(): Promise<BatchResult>;
|
|
84
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RedisClient } from 'bun';
|
|
2
|
+
export declare interface LockOptions {
|
|
3
|
+
duration?: number
|
|
4
|
+
autoExtend?: boolean
|
|
5
|
+
extendInterval?: number
|
|
6
|
+
retries?: number
|
|
7
|
+
retryDelay?: number
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Distributed lock implementation using Redis
|
|
11
|
+
*/
|
|
12
|
+
export declare class DistributedLock {
|
|
13
|
+
private redisClient: RedisClient;
|
|
14
|
+
private prefix: string;
|
|
15
|
+
readonly private logger: any;
|
|
16
|
+
constructor(redisClient: RedisClient, prefix?: any);
|
|
17
|
+
acquire(resource: string, options?: LockOptions): Promise<string | null>;
|
|
18
|
+
release(resource: string, token: string): Promise<boolean>;
|
|
19
|
+
isLocked(resource: string): Promise<boolean>;
|
|
20
|
+
extend(resource: string, token: string, duration: number): Promise<boolean>;
|
|
21
|
+
private setupAutoExtend(resource: string, token: string, duration: number, interval: number): void;
|
|
22
|
+
private getLockKey(resource: string): string;
|
|
23
|
+
static private autoExtendTimers: any;
|
|
24
|
+
withLock<T>(resource: string, fn: () => Promise<T>, options?: LockOptions): Promise<T>;
|
|
25
|
+
}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
declare class JobEvents extends EventEmitter {
|
|
3
|
+
readonly private logger: any;
|
|
4
|
+
readonly private queueName: string;
|
|
5
|
+
constructor(queueName: string);
|
|
6
|
+
emitJobAdded(jobId: string, name: string): void;
|
|
7
|
+
emitJobRemoved(jobId: string): void;
|
|
8
|
+
emitJobCompleted(jobId: string, result: any): void;
|
|
9
|
+
emitJobFailed(jobId: string, error: Error): void;
|
|
10
|
+
emitJobProgress(jobId: string, progress: number): void;
|
|
11
|
+
emitJobActive(jobId: string): void;
|
|
12
|
+
emitJobStalled(jobId: string): void;
|
|
13
|
+
emitJobDelayed(jobId: string, delay: number): void;
|
|
14
|
+
emitReady(): void;
|
|
15
|
+
emitError(error: Error): void;
|
|
16
|
+
emitBatchAdded(batchId: string, jobIds: string[]): void;
|
|
17
|
+
emitBatchCompleted(batchId: string, results: any[]): void;
|
|
18
|
+
emitBatchFailed(batchId: string, errors: Error[]): void;
|
|
19
|
+
emitBatchProgress(batchId: string, progress: number): void;
|
|
20
|
+
emitGroupCreated(groupName: string): void;
|
|
21
|
+
emitGroupRemoved(groupName: string): void;
|
|
22
|
+
emitObservableStarted(observableId: string): void;
|
|
23
|
+
emitObservableStopped(observableId: string): void;
|
|
24
|
+
emitJobMovedToDeadLetter(jobId: string, deadLetterQueueName: string, reason: string): void;
|
|
25
|
+
emitJobRepublishedFromDeadLetter(jobId: string, originalQueueName: string): void;
|
|
26
|
+
}
|
|
27
|
+
export { JobEvents };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FailedJob, FailedJobProvider } from './failed-job-provider';
|
|
2
|
+
export declare class FailedJobManager {
|
|
3
|
+
private provider: FailedJobProvider;
|
|
4
|
+
private logger: any;
|
|
5
|
+
constructor(driver?: 'redis' | 'database', options?: any);
|
|
6
|
+
log(connection: string, queue: string, payload: string, exception: Error): Promise<string>;
|
|
7
|
+
all(): Promise<FailedJob[]>;
|
|
8
|
+
find(id: string): Promise<FailedJob | null>;
|
|
9
|
+
retry(id: string): Promise<boolean>;
|
|
10
|
+
forget(id: string): Promise<boolean>;
|
|
11
|
+
flush(hours?: number): Promise<void>;
|
|
12
|
+
prune(hours?: number): Promise<number>;
|
|
13
|
+
count(): Promise<number>;
|
|
14
|
+
retryAll(): Promise<number>;
|
|
15
|
+
getFailedJobsByQueue(queue: string): Promise<FailedJob[]>;
|
|
16
|
+
getFailedJobsByConnection(connection: string): Promise<FailedJob[]>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
export declare interface FailedJob {
|
|
3
|
+
id: string
|
|
4
|
+
connection: string
|
|
5
|
+
queue: string
|
|
6
|
+
payload: string
|
|
7
|
+
exception: string
|
|
8
|
+
failed_at: Date
|
|
9
|
+
}
|
|
10
|
+
export declare interface FailedJobProvider {
|
|
11
|
+
log: (connection: string, queue: string, payload: string, exception: Error) => Promise<string>
|
|
12
|
+
all: () => Promise<FailedJob[]>
|
|
13
|
+
find: (id: string) => Promise<FailedJob | null>
|
|
14
|
+
forget: (id: string) => Promise<boolean>
|
|
15
|
+
flush: (hours?: number) => Promise<void>
|
|
16
|
+
prune: (hours: number) => Promise<number>
|
|
17
|
+
}
|
|
18
|
+
export declare class RedisFailedJobProvider implements FailedJobProvider {
|
|
19
|
+
private prefix: string;
|
|
20
|
+
constructor(prefix?: string);
|
|
21
|
+
log(_connection: string, _queue: string, _payload: string, _exception: Error): Promise<string>;
|
|
22
|
+
all(): Promise<FailedJob[]>;
|
|
23
|
+
find(id: string): Promise<FailedJob | null>;
|
|
24
|
+
forget(id: string): Promise<boolean>;
|
|
25
|
+
flush(hours?: number): Promise<void>;
|
|
26
|
+
prune(hours: number): Promise<number>;
|
|
27
|
+
}
|
|
28
|
+
export declare class DatabaseFailedJobProvider implements FailedJobProvider {
|
|
29
|
+
private table: string;
|
|
30
|
+
constructor(table?: string);
|
|
31
|
+
log(_connection: string, _queue: string, _payload: string, _exception: Error): Promise<string>;
|
|
32
|
+
all(): Promise<FailedJob[]>;
|
|
33
|
+
find(id: string): Promise<FailedJob | null>;
|
|
34
|
+
forget(id: string): Promise<boolean>;
|
|
35
|
+
flush(hours?: number): Promise<void>;
|
|
36
|
+
prune(hours: number): Promise<number>;
|
|
37
|
+
}
|
package/dist/group.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { RedisClient } from 'bun';
|
|
2
|
+
import type { Group, GroupOptions, Job } from './types';
|
|
3
|
+
import type { Queue } from './queue';
|
|
4
|
+
import type { Worker } from './worker';
|
|
5
|
+
export declare class QueueGroup<T = any> {
|
|
6
|
+
readonly private redisClient: RedisClient;
|
|
7
|
+
readonly private prefix: string;
|
|
8
|
+
readonly private queues: Map<string, Queue<T>>;
|
|
9
|
+
private workers: Map<string, Worker<T>>;
|
|
10
|
+
readonly private logger: any;
|
|
11
|
+
constructor(prefix: string, redisClient: RedisClient);
|
|
12
|
+
addQueue(queue: Queue<T>, options?: GroupOptions): Promise<void>;
|
|
13
|
+
removeQueue(queueName: string, groupName?: string): Promise<void>;
|
|
14
|
+
getAllGroups(): Promise<Group[]>;
|
|
15
|
+
getGroup(groupName: string): Promise<Group | null>;
|
|
16
|
+
processGroup<R = any>(groupName: string, handler: (job: Job<T>) => Promise<R>): Promise<void>;
|
|
17
|
+
addJobToGroup(groupName: string, data: T): Promise<Job<T>[]>;
|
|
18
|
+
closeGroup(groupName: string): Promise<void>;
|
|
19
|
+
closeAll(): Promise<void>;
|
|
20
|
+
private getGroupKey(groupName: string): string;
|
|
21
|
+
private getGroupMetaKey(groupName: string): string;
|
|
22
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export type { QueueConnectionConfig, QueueManagerConfig } from './types';
|
|
2
|
+
export { BatchProcessor } from './batch';
|
|
3
|
+
export { config } from './config';
|
|
4
|
+
export { DeadLetterQueue } from './dead-letter-queue';
|
|
5
|
+
export {
|
|
6
|
+
batch,
|
|
7
|
+
type Batch,
|
|
8
|
+
type BatchOptions,
|
|
9
|
+
type BatchResult,
|
|
10
|
+
chain,
|
|
11
|
+
dispatch,
|
|
12
|
+
DispatchableChain,
|
|
13
|
+
dispatchAfter,
|
|
14
|
+
dispatchChain,
|
|
15
|
+
type DispatchChain,
|
|
16
|
+
dispatchFunction,
|
|
17
|
+
dispatchIf,
|
|
18
|
+
dispatchSync,
|
|
19
|
+
dispatchUnless,
|
|
20
|
+
JobBatch,
|
|
21
|
+
type QueuedClosure,
|
|
22
|
+
} from './dispatch';
|
|
23
|
+
export { DistributedLock } from './distributed-lock';
|
|
24
|
+
export { JobEvents } from './events';
|
|
25
|
+
export * from './failed';
|
|
26
|
+
export { QueueGroup } from './group';
|
|
27
|
+
export { Job } from './job';
|
|
28
|
+
export {
|
|
29
|
+
type Dispatchable,
|
|
30
|
+
type InteractsWithQueue,
|
|
31
|
+
JobBase,
|
|
32
|
+
type JobContract,
|
|
33
|
+
type JobMiddleware,
|
|
34
|
+
type ShouldQueue,
|
|
35
|
+
} from './job-base';
|
|
36
|
+
export {
|
|
37
|
+
createJobProcessor,
|
|
38
|
+
getGlobalJobProcessor,
|
|
39
|
+
JobProcessor,
|
|
40
|
+
type JobProcessorOptions,
|
|
41
|
+
setGlobalJobProcessor,
|
|
42
|
+
} from './job-processor';
|
|
43
|
+
export * from './jobs';
|
|
44
|
+
export { LeaderElection } from './leader-election';
|
|
45
|
+
export { createLogger } from './logger';
|
|
46
|
+
export {
|
|
47
|
+
FailureMiddleware,
|
|
48
|
+
JobMiddlewareStack,
|
|
49
|
+
middleware,
|
|
50
|
+
type MiddlewareStack,
|
|
51
|
+
RateLimitMiddleware,
|
|
52
|
+
SkipIfMiddleware,
|
|
53
|
+
ThrottleMiddleware,
|
|
54
|
+
UniqueJobMiddleware,
|
|
55
|
+
WithoutOverlappingMiddleware,
|
|
56
|
+
} from './middleware';
|
|
57
|
+
export { QueueObservable } from './observable';
|
|
58
|
+
export { PriorityQueue } from './priority-queue';
|
|
59
|
+
export { Queue } from './queue';
|
|
60
|
+
export {
|
|
61
|
+
closeQueueManager,
|
|
62
|
+
getQueueManager as getManager,
|
|
63
|
+
getQueueManager,
|
|
64
|
+
type QueueConnection,
|
|
65
|
+
QueueManager,
|
|
66
|
+
setQueueManager,
|
|
67
|
+
} from './queue-manager';
|
|
68
|
+
export { RateLimiter } from './rate-limiter';
|
|
69
|
+
export * from './types';
|
|
70
|
+
export { WorkCoordinator } from './work-coordinator';
|
|
71
|
+
export { Worker } from './worker';
|
|
72
|
+
export * from './workers';
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Job } from './job';
|
|
2
|
+
export declare function getQueueManager(): Promise<QueueManager>;
|
|
3
|
+
export declare interface ShouldQueue {
|
|
4
|
+
handle: (...args: any[]) => Promise<any> | any
|
|
5
|
+
}
|
|
6
|
+
export declare interface ShouldBeUnique {
|
|
7
|
+
uniqueId: () => string
|
|
8
|
+
}
|
|
9
|
+
export declare interface ShouldBatch {
|
|
10
|
+
batchId?: string
|
|
11
|
+
}
|
|
12
|
+
export declare interface Queueable {
|
|
13
|
+
onQueue: (queue: string) => this
|
|
14
|
+
onConnection: (connection: string) => this
|
|
15
|
+
withDelay: (delay: number) => this
|
|
16
|
+
allOnQueue: (queue: string) => this
|
|
17
|
+
allOnConnection: (connection: string) => this
|
|
18
|
+
}
|
|
19
|
+
export declare interface JobContract extends ShouldQueue {
|
|
20
|
+
queue?: string
|
|
21
|
+
connection?: string
|
|
22
|
+
delay?: number
|
|
23
|
+
tries?: number
|
|
24
|
+
timeout?: number
|
|
25
|
+
backoff?: number[]
|
|
26
|
+
maxExceptions?: number
|
|
27
|
+
deleteWhenMissingModels?: boolean
|
|
28
|
+
middleware?: JobMiddleware[]
|
|
29
|
+
uniqueId?: () => string | undefined
|
|
30
|
+
tags?: string[]
|
|
31
|
+
failOnTimeout?: boolean
|
|
32
|
+
job?: Job<any>
|
|
33
|
+
dispatch?: (...args: any[]) => Promise<Job<any>>
|
|
34
|
+
dispatchSync?: (...args: any[]) => Promise<any>
|
|
35
|
+
dispatchIf?: (condition: boolean, ...args: any[]) => Promise<Job<any> | null>
|
|
36
|
+
dispatchUnless?: (condition: boolean, ...args: any[]) => Promise<Job<any> | null>
|
|
37
|
+
dispatchAfter?: (delay: number, ...args: any[]) => Promise<Job<any>>
|
|
38
|
+
}
|
|
39
|
+
export declare interface JobMiddleware {
|
|
40
|
+
handle: (job: JobContract, next: () => Promise<void>) => Promise<void>
|
|
41
|
+
}
|
|
42
|
+
export declare interface Dispatchable {
|
|
43
|
+
dispatch: (...args: any[]) => Promise<Job<any>>
|
|
44
|
+
dispatchSync: (...args: any[]) => Promise<any>
|
|
45
|
+
dispatchIf: (condition: boolean, ...args: any[]) => Promise<Job<any> | null>
|
|
46
|
+
dispatchUnless: (condition: boolean, ...args: any[]) => Promise<Job<any> | null>
|
|
47
|
+
dispatchAfter: (delay: number, ...args: any[]) => Promise<Job<any>>
|
|
48
|
+
}
|
|
49
|
+
export declare interface InteractsWithQueue {
|
|
50
|
+
job?: Job<any>
|
|
51
|
+
fail: (exception?: Error) => Promise<void>
|
|
52
|
+
release: (delay?: number) => Promise<void>
|
|
53
|
+
delete: () => Promise<void>
|
|
54
|
+
}
|
|
55
|
+
export declare interface QueueManager {
|
|
56
|
+
connection: (name?: string) => QueueConnection
|
|
57
|
+
queue: (name?: string) => any
|
|
58
|
+
}
|
|
59
|
+
export declare interface QueueConnection {
|
|
60
|
+
queue: (name?: string) => any
|
|
61
|
+
}
|
|
62
|
+
export declare abstract class JobBase implements JobContract, Queueable, Dispatchable, InteractsWithQueue {
|
|
63
|
+
queue?: string;
|
|
64
|
+
connection?: string;
|
|
65
|
+
delay?: number;
|
|
66
|
+
tries?: number;
|
|
67
|
+
timeout?: number;
|
|
68
|
+
backoff?: number[];
|
|
69
|
+
maxExceptions?: number;
|
|
70
|
+
deleteWhenMissingModels?: boolean;
|
|
71
|
+
middleware?: JobMiddleware[];
|
|
72
|
+
tags?: string[];
|
|
73
|
+
failOnTimeout?: boolean;
|
|
74
|
+
job?: Job<any>;
|
|
75
|
+
abstract handle(args: any[]): Promise<any> | any;
|
|
76
|
+
dispatch(args: any[]): Promise<Job<any>>;
|
|
77
|
+
dispatchSync(args: any[]): Promise<any>;
|
|
78
|
+
dispatchIf(condition: boolean, args: any[]): Promise<Job<any> | null>;
|
|
79
|
+
dispatchUnless(condition: boolean, args: any[]): Promise<Job<any> | null>;
|
|
80
|
+
dispatchAfter(delay: number, args: any[]): Promise<Job<any>>;
|
|
81
|
+
onQueue(queue: string): this;
|
|
82
|
+
onConnection(connection: string): this;
|
|
83
|
+
withDelay(delay: number): this;
|
|
84
|
+
allOnQueue(queue: string): this;
|
|
85
|
+
allOnConnection(connection: string): this;
|
|
86
|
+
withTries(tries: number): this;
|
|
87
|
+
withTimeout(timeout: number): this;
|
|
88
|
+
withBackoff(backoff: number[]): this;
|
|
89
|
+
withMiddleware(middleware: JobMiddleware[]): this;
|
|
90
|
+
withTags(tags: string[]): this;
|
|
91
|
+
fail(exception?: Error): Promise<void>;
|
|
92
|
+
release(delay?: number): Promise<void>;
|
|
93
|
+
delete(): Promise<void>;
|
|
94
|
+
uniqueId(): string | undefined;
|
|
95
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Job } from './job';
|
|
2
|
+
import type { JobContract } from './job-base';
|
|
3
|
+
// Utility function to create a processor for job classes
|
|
4
|
+
export declare function createJobProcessor(options?: JobProcessorOptions): JobProcessor;
|
|
5
|
+
export declare function getGlobalJobProcessor(options?: JobProcessorOptions): JobProcessor;
|
|
6
|
+
export declare function setGlobalJobProcessor(processor: JobProcessor): void;
|
|
7
|
+
export declare interface JobProcessorOptions {
|
|
8
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
9
|
+
}
|
|
10
|
+
export declare class JobProcessor {
|
|
11
|
+
private logger: any;
|
|
12
|
+
constructor(options?: JobProcessorOptions);
|
|
13
|
+
process(job: Job<any>): Promise<any>;
|
|
14
|
+
private isJobClass(data: any): boolean;
|
|
15
|
+
private processJobClass(job: Job<any>, jobData: any): Promise<any>;
|
|
16
|
+
private processWithMiddleware(jobInstance: JobContract, args: any[]): Promise<any>;
|
|
17
|
+
private executeJob(jobInstance: JobContract, args: any[]): Promise<any>;
|
|
18
|
+
private shouldSkipJob(_jobInstance: JobContract): boolean;
|
|
19
|
+
private processDataJob(job: Job<any>, data: any): Promise<any>;
|
|
20
|
+
processWithTimeout(job: Job<any>, timeout?: number): Promise<any>;
|
|
21
|
+
}
|
package/dist/job.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { JobOptions } from './types';
|
|
2
|
+
import type { Queue } from './queue';
|
|
3
|
+
export declare class Job<T = any> {
|
|
4
|
+
queue: Queue<T>;
|
|
5
|
+
id: string;
|
|
6
|
+
data: T;
|
|
7
|
+
name: string;
|
|
8
|
+
opts: JobOptions;
|
|
9
|
+
progress: number;
|
|
10
|
+
delay: number;
|
|
11
|
+
timestamp: number;
|
|
12
|
+
attemptsMade: number;
|
|
13
|
+
stacktrace: string[];
|
|
14
|
+
returnvalue: any;
|
|
15
|
+
finishedOn?: number;
|
|
16
|
+
processedOn?: number;
|
|
17
|
+
failedReason?: string;
|
|
18
|
+
dependencies?: string[];
|
|
19
|
+
constructor(queue: Queue<T>, jobId: string);
|
|
20
|
+
refresh(): Promise<void>;
|
|
21
|
+
updateProgress(progress: number): Promise<void>;
|
|
22
|
+
moveToCompleted(returnvalue?: any): Promise<void>;
|
|
23
|
+
moveToFailed(err: Error, failedReason?: string): Promise<void>;
|
|
24
|
+
retry(): Promise<void>;
|
|
25
|
+
remove(): Promise<void>;
|
|
26
|
+
private processDependents(): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare interface BatchableJob extends Job {
|
|
2
|
+
batchId?: string
|
|
3
|
+
allowFailures?: boolean
|
|
4
|
+
}
|
|
5
|
+
export declare interface Batch {
|
|
6
|
+
id: string
|
|
7
|
+
name?: string
|
|
8
|
+
totalJobs: number
|
|
9
|
+
pendingJobs: number
|
|
10
|
+
processedJobs: number
|
|
11
|
+
failedJobs: number
|
|
12
|
+
createdAt: Date
|
|
13
|
+
finishedAt?: Date
|
|
14
|
+
cancelledAt?: Date
|
|
15
|
+
}
|
|
16
|
+
export declare interface PendingBatch {
|
|
17
|
+
add: (jobs: Job | Job[]) => this
|
|
18
|
+
before: (callback: (batch: Batch) => void) => this
|
|
19
|
+
progress: (callback: (batch: Batch) => void) => this
|
|
20
|
+
then: (callback: (batch: Batch) => void) => this
|
|
21
|
+
catch: (callback: (batch: Batch, error: Error) => void) => this
|
|
22
|
+
finally: (callback: (batch: Batch) => void) => this
|
|
23
|
+
allowFailures: (failures?: number) => this
|
|
24
|
+
onQueue: (queue: string) => this
|
|
25
|
+
onConnection: (connection: string) => this
|
|
26
|
+
dispatch: () => Promise<Batch>
|
|
27
|
+
}
|
|
28
|
+
export declare class JobBatch implements PendingBatch {
|
|
29
|
+
private jobs: Job[];
|
|
30
|
+
private beforeCallbacks: Array<(batch: Batch) => void>;
|
|
31
|
+
private progressCallbacks: Array<(batch: Batch) => void>;
|
|
32
|
+
private thenCallbacks: Array<(batch: Batch) => void>;
|
|
33
|
+
private catchCallbacks: Array<(batch: Batch, error: Error) => void>;
|
|
34
|
+
private finallyCallbacks: Array<(batch: Batch) => void>;
|
|
35
|
+
private allowedFailures?: number;
|
|
36
|
+
private queueName?: string;
|
|
37
|
+
private connectionName?: string;
|
|
38
|
+
private batchName?: string;
|
|
39
|
+
constructor(batchName?: string);
|
|
40
|
+
add(jobs: Job | Job[]): this;
|
|
41
|
+
before(callback: (batch: Batch) => void): this;
|
|
42
|
+
progress(callback: (batch: Batch) => void): this;
|
|
43
|
+
then(callback: (batch: Batch) => void): this;
|
|
44
|
+
catch(callback: (batch: Batch, error: Error) => void): this;
|
|
45
|
+
finally(callback: (batch: Batch) => void): this;
|
|
46
|
+
allowFailures(failures?: number): this;
|
|
47
|
+
onQueue(queue: string): this;
|
|
48
|
+
onConnection(connection: string): this;
|
|
49
|
+
dispatch(): Promise<Batch>;
|
|
50
|
+
private monitorJob(queueJob: QueueJob<any>, batch: Batch, _jobIndex: number): Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
export declare class Bus {
|
|
53
|
+
static batch(name?: string): PendingBatch;
|
|
54
|
+
static dispatch(job: Job, args: any[]): Promise<QueueJob<any>>;
|
|
55
|
+
static dispatchSync(job: Job, args: any[]): Promise<any>;
|
|
56
|
+
static dispatchIf(condition: boolean, job: Job, args: any[]): Promise<QueueJob<any> | null>;
|
|
57
|
+
static dispatchUnless(condition: boolean, job: Job, args: any[]): Promise<QueueJob<any> | null>;
|
|
58
|
+
static dispatchAfter(delay: number, job: Job, args: any[]): Promise<QueueJob<any>>;
|
|
59
|
+
static chain(jobs: Job[]): Promise<QueueJob<any>[]>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { dispatch, dispatchAfter, dispatchIf, dispatchSync, dispatchUnless } from '../dispatch';
|
|
2
|
+
export {
|
|
3
|
+
type Dispatchable,
|
|
4
|
+
type InteractsWithQueue,
|
|
5
|
+
JobBase as Job,
|
|
6
|
+
type JobContract,
|
|
7
|
+
type JobMiddleware,
|
|
8
|
+
type Queueable,
|
|
9
|
+
type ShouldBatch,
|
|
10
|
+
type ShouldBeUnique,
|
|
11
|
+
type ShouldQueue,
|
|
12
|
+
} from '../job-base';
|
|
13
|
+
export { Bus } from './bus';
|
|
14
|
+
export * from './middleware';
|