@workglow/job-queue 0.0.56 → 0.0.58

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.
@@ -1,160 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { IQueueStorage, JobStatus } from "@workglow/storage";
7
- import { ILimiter } from "../limiter/ILimiter";
8
- import { Job } from "./Job";
9
- import { JobQueueStats } from "./JobQueue";
10
- import { JobProgressListener } from "./JobQueueEventListeners";
11
- export { JobStatus };
12
- /**
13
- * Common options for all job queues
14
- */
15
- export interface JobQueueOptions<Input, Output> {
16
- /**
17
- * Time in milliseconds after which completed jobs should be deleted
18
- * Set to 0 to delete immediately, undefined to never delete
19
- */
20
- deleteAfterCompletionMs?: number;
21
- /**
22
- * Time in milliseconds after which failed jobs should be deleted
23
- * Set to 0 to delete immediately, undefined to never delete
24
- */
25
- deleteAfterFailureMs?: number;
26
- /**
27
- * Time in milliseconds after which disabled jobs should be deleted
28
- * Set to 0 to delete immediately, undefined to never delete
29
- */
30
- deleteAfterDisabledMs?: number;
31
- /**
32
- * How often to check for new jobs in milliseconds
33
- */
34
- waitDurationInMilliseconds?: number;
35
- /**
36
- * Rate limiter to control job execution
37
- */
38
- limiter?: ILimiter;
39
- /**
40
- * Storage to use for the job queue
41
- */
42
- storage?: IQueueStorage<Input, Output>;
43
- } /**
44
- * Defines how a job queue operates in different contexts
45
- */
46
- export declare enum QueueMode {
47
- /**
48
- * Queue operates in client mode only - can submit jobs and receive progress updates
49
- * but does not process jobs
50
- */
51
- CLIENT = "CLIENT",
52
- /**
53
- * Queue operates in server mode only - processes jobs but does not accept new submissions
54
- */
55
- SERVER = "SERVER",
56
- /**
57
- * Queue operates in both client and server mode - can submit and process jobs
58
- */
59
- BOTH = "BOTH"
60
- }
61
- /**
62
- * Interface for a job queue
63
- */
64
- export interface IJobQueue<Input, Output> {
65
- /**
66
- * The name of the queue
67
- */
68
- queueName: string;
69
- /**
70
- * Add a job to the queue
71
- * @param job The job to add
72
- * @returns A promise that resolves to the job ID
73
- */
74
- add(job: Job<Input, Output>): Promise<unknown>;
75
- /**
76
- * Get a job by its ID
77
- * @param id The job ID
78
- * @returns A promise that resolves to the job, or undefined if not found
79
- */
80
- get(id: unknown): Promise<Job<Input, Output> | undefined>;
81
- /**
82
- * Wait for a job to complete
83
- * @param jobId The job ID to wait for
84
- * @returns A promise that resolves to the job output, or rejects with an error
85
- */
86
- waitFor(jobId: unknown): Promise<Output | undefined>;
87
- /**
88
- * Abort a job
89
- * @param jobId The job ID to abort
90
- * @returns A promise that resolves to true if the job was aborted, false otherwise
91
- */
92
- abort(jobId: unknown): Promise<void>;
93
- /**
94
- * Peek at jobs in the queue
95
- * @param status Optional status to filter by
96
- * @param num Optional number of jobs to return
97
- * @returns A promise that resolves to an array of jobs
98
- */
99
- peek(status?: JobStatus, num?: number): Promise<Job<Input, Output>[]>;
100
- /**
101
- * Get the size of the queue
102
- * @param status Optional status to filter by
103
- * @returns A promise that resolves to the number of jobs
104
- */
105
- size(status?: JobStatus): Promise<number>;
106
- /**
107
- * Get the output for a job by its input
108
- * @param input The job input
109
- * @returns A promise that resolves to the job output, or null if not found
110
- */
111
- outputForInput(input: Input): Promise<Output | null>;
112
- /**
113
- * Get jobs by their run ID
114
- * @param jobRunId The job run ID
115
- * @returns A promise that resolves to an array of jobs
116
- */
117
- getJobsByRunId(jobRunId: string): Promise<Job<Input, Output>[]>;
118
- /**
119
- * Get the stats for the job queue
120
- * @returns The job queue stats
121
- */
122
- getStats(): JobQueueStats;
123
- /**
124
- * Update the progress of a job
125
- * @param jobId The job ID
126
- * @param progress The progress value
127
- * @param message Optional message to set
128
- * @param details Optional details to set
129
- * @returns A promise that resolves when the progress is updated
130
- */
131
- updateProgress(jobId: unknown, progress: number, message?: string, details?: Record<string, any> | null): Promise<void>;
132
- onJobProgress(jobId: unknown, listener: JobProgressListener): () => void;
133
- /**
134
- * Start the job queue
135
- * @param mode Optional mode to set
136
- * @returns A promise that resolves to the job queue
137
- */
138
- start(mode?: QueueMode): Promise<this>;
139
- /**
140
- * Stop the job queue
141
- * @returns A promise that resolves to the job queue
142
- */
143
- stop(): Promise<this>;
144
- /**
145
- * Clear the job queue
146
- * @returns A promise that resolves to the job queue
147
- */
148
- clear(): Promise<this>;
149
- /**
150
- * Restart the job queue
151
- * @returns A promise that resolves to the job queue
152
- */
153
- restart(): Promise<this>;
154
- /**
155
- * Get the next job from the queue
156
- * @returns A promise that resolves to the next job, or undefined if the queue is empty
157
- */
158
- next(): Promise<Job<Input, Output> | undefined>;
159
- }
160
- //# sourceMappingURL=IJobQueue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"IJobQueue.d.ts","sourceRoot":"","sources":["../../src/job/IJobQueue.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB;;GAEG;AAEH,MAAM,WAAW,eAAe,CAAC,KAAK,EAAE,MAAM;IAC5C;;;OAGG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;OAGG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;OAEG;IACH,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC;;OAEG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa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IAE1B;;;;;;;OAOG;IACH,cAAc,CACZ,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GACnC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,GAAG,MAAM,IAAI,CAAC;IAEzE;;;;OAIG;IACH,KAAK,CAAC,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC;CACjD"}
@@ -1,272 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { IQueueStorage, JobStorageFormat } from "@workglow/storage";
7
- import { EventEmitter } from "@workglow/util";
8
- import { ILimiter } from "../limiter/ILimiter";
9
- import { IJobQueue, JobQueueOptions, JobStatus, QueueMode } from "./IJobQueue";
10
- import { Job, JobConstructorParam } from "./Job";
11
- import { JobError } from "./JobError";
12
- import { JobProgressListener, JobQueueEventListener, JobQueueEventListeners, JobQueueEventParameters, JobQueueEvents } from "./JobQueueEventListeners";
13
- /**
14
- * Statistics tracked for the job queue
15
- */
16
- export interface JobQueueStats {
17
- totalJobs: number;
18
- completedJobs: number;
19
- failedJobs: number;
20
- abortedJobs: number;
21
- retriedJobs: number;
22
- disabledJobs: number;
23
- averageProcessingTime?: number;
24
- lastUpdateTime: Date;
25
- }
26
- type JobClass<Input, Output> = new (param: JobConstructorParam<Input, Output>) => Job<Input, Output>;
27
- /**
28
- * Base class for implementing job queues with different storage backends.
29
- */
30
- export declare class JobQueue<Input, Output, QueueJob extends Job<Input, Output> = Job<Input, Output>> implements IJobQueue<Input, Output> {
31
- /**
32
- * The name of the queue
33
- */
34
- readonly queueName: string;
35
- /**
36
- * The class of the job to be used in the queue
37
- */
38
- readonly jobClass: JobClass<Input, Output>;
39
- /**
40
- * The options for the queue
41
- */
42
- protected options: JobQueueOptions<Input, Output>;
43
- constructor(queueName: string, jobClass: JobClass<Input, Output>, options: JobQueueOptions<Input, Output>);
44
- /**
45
- * Gets a job from the queue
46
- * @param id The ID of the job to get
47
- */
48
- get(id: unknown): Promise<Job<Input, Output> | undefined>;
49
- /**
50
- * Adds a job to the queue
51
- * @param job The job to add
52
- */
53
- add(job: QueueJob): Promise<unknown>;
54
- /**
55
- * Gets the next job from the queue
56
- */
57
- next(): Promise<Job<Input, Output> | undefined>;
58
- /**
59
- * Peek into the queue
60
- * @param status The status of the job to peek at
61
- * @param num The number of jobs to peek at
62
- */
63
- peek(status?: JobStatus, num?: number): Promise<Job<Input, Output>[]>;
64
- /**
65
- * Gets the size of the queue
66
- * @param status The status of the jobs to get the size of
67
- */
68
- size(status?: JobStatus): Promise<number>;
69
- /**
70
- * Deletes a job from the queue
71
- * @param id The ID of the job to delete
72
- */
73
- delete(id: unknown): Promise<void>;
74
- disable(id: unknown): Promise<void>;
75
- /**
76
- * Returns current queue statistics
77
- */
78
- getStats(): JobQueueStats;
79
- /**
80
- * Gets the output for an input
81
- * @param input The input to get the output for
82
- */
83
- outputForInput(input: Input): Promise<Output | null>;
84
- /**
85
- * Executes a job with the provided abort signal.
86
- * Can be overridden by implementations to add custom execution logic.
87
- */
88
- executeJob(job: Job<Input, Output>, signal: AbortSignal): Promise<Output>;
89
- /**
90
- * Returns a promise that resolves when the job completes
91
- */
92
- waitFor(jobId: unknown): Promise<Output | undefined>;
93
- /**
94
- * Reconstructs an error instance from a stored failed job
95
- */
96
- protected buildErrorFromJob(job: Job<Input, Output>): JobError;
97
- /**
98
- * Updates the progress of a job
99
- * @param jobId - The ID of the job to update
100
- * @param progress - Progress value between 0 and 100
101
- * @param message - Optional message describing the current progress state
102
- * @param details - Optional structured data about the progress
103
- * @returns A promise that resolves when the progress is updated
104
- * @note If the job is completed, failed, or aborted, the progress will not be updated
105
- */
106
- updateProgress(jobId: unknown, progress: number, message?: string, details?: Record<string, any> | null): Promise<void>;
107
- /**
108
- * Adds a progress listener for a specific job
109
- * @param jobId - The ID of the job to listen to
110
- * @param listener - The callback function to be called when progress updates occur
111
- * @returns A cleanup function to remove the listener
112
- */
113
- onJobProgress(jobId: unknown, listener: JobProgressListener): () => void;
114
- /**
115
- * Starts the job queue based on its operating mode
116
- */
117
- start(mode?: QueueMode): Promise<this>;
118
- /**
119
- * Stops the job queue and aborts all active jobs
120
- */
121
- stop(): Promise<this>;
122
- /**
123
- * Clears all jobs and resets queue state
124
- */
125
- clear(): Promise<this>;
126
- /**
127
- * Restarts the job queue
128
- */
129
- restart(): Promise<this>;
130
- /**
131
- * Aborts all jobs in a job run
132
- */
133
- abortJobRun(jobRunId: string): Promise<void>;
134
- /**
135
- * Gets jobs by run ID
136
- * @param runId The ID of the run to get jobs for
137
- */
138
- getJobsByRunId(runId: string): Promise<Job<Input, Output>[]>;
139
- /**
140
- * Registers an event listener for job queue events
141
- */
142
- on<Event extends JobQueueEvents>(event: Event, listener: JobQueueEventListener<Event>): void;
143
- /**
144
- * Removes an event listener for job queue events
145
- */
146
- off<Event extends JobQueueEvents>(event: Event, listener: JobQueueEventListener<Event>): void;
147
- /**
148
- * Adds an event listener for job queue events that will be called only once
149
- */
150
- once<Event extends JobQueueEvents>(event: Event, listener: JobQueueEventListener<Event>): void;
151
- /**
152
- * Returns a promise that resolves when the event is emitted
153
- */
154
- waitOn<Event extends JobQueueEvents>(event: Event): Promise<JobQueueEventParameters<Event, Input, Output>>;
155
- /**
156
- * The limiter for the queue
157
- */
158
- protected readonly limiter: ILimiter;
159
- /**
160
- * The storage for the queue
161
- */
162
- protected readonly storage: IQueueStorage<Input, Output>;
163
- /**
164
- * Whether the queue is running
165
- */
166
- protected running: boolean;
167
- /**
168
- * The stats for the queue
169
- */
170
- protected stats: JobQueueStats;
171
- /**
172
- * The event emitter for the queue
173
- */
174
- protected events: EventEmitter<JobQueueEventListeners<Input, Output>>;
175
- /**
176
- * The map of jobs to their promises for this worker instance
177
- */
178
- protected activeJobAbortControllers: Map<unknown, AbortController>;
179
- /**
180
- * Map of jobs to their promises for this worker instance
181
- * If this is both a server and client we can short-circuit
182
- * job aborting, wait on job completion, etc.
183
- */
184
- protected activeJobPromises: Map<unknown, Array<{
185
- resolve: (value?: any) => void;
186
- reject: (err: JobError) => void;
187
- }>>;
188
- protected processingTimes: Map<unknown, number>;
189
- protected mode: QueueMode;
190
- protected jobProgressListeners: Map<unknown, Set<JobProgressListener>>;
191
- protected lastKnownProgress: Map<unknown, {
192
- progress: number;
193
- message: string;
194
- details: Record<string, any> | null;
195
- }>;
196
- /**
197
- * Saves the progress for a job
198
- * @param id The ID of the job to save progress for
199
- * @param progress The progress of the job
200
- * @param message The message of the job
201
- * @param details The details of the job
202
- */
203
- private saveProgress;
204
- /**
205
- * Creates an abort controller for a job and adds it to the activeJobSignals map
206
- */
207
- protected createAbortController(jobId: unknown): AbortController;
208
- /**
209
- * Validates the state of a job before processing
210
- */
211
- protected validateJobState(job: Job<Input, Output>): Promise<void>;
212
- /**
213
- * Normalizes different types of errors into JobError instances
214
- */
215
- protected normalizeError(err: any): JobError;
216
- /**
217
- * Updates average processing time statistics
218
- */
219
- protected updateAverageProcessingTime(): void;
220
- /**
221
- * Emits updated statistics
222
- */
223
- protected emitStatsUpdate(): void;
224
- protected announceProgress(jobId: unknown, progress: number, message: string, details: Record<string, any> | null): void;
225
- /**
226
- * Creates a new job instance from the provided database results.
227
- * @param details - The job data from the database
228
- * @returns A new Job instance with populated properties
229
- */
230
- protected storageToClass(details: JobStorageFormat<Input, Output>): Job<Input, Output>;
231
- /**
232
- * Converts a Job instance to a JobDetails object
233
- * @param job - The Job instance to convert
234
- * @returns A JobDetails object with the same properties as the Job instance
235
- */
236
- classToStorage(job: Job<Input, Output>): JobStorageFormat<Input, Output>;
237
- protected rescheduleJob(job: Job<Input, Output>, retryDate?: Date): Promise<void>;
238
- protected disableJob(job: Job<Input, Output>): Promise<void>;
239
- protected failJob(job: Job<Input, Output>, error: JobError): Promise<void>;
240
- protected completeJob(job: Job<Input, Output>, output?: Output): Promise<void>;
241
- /**
242
- * Signals the abort of a job
243
- * @param jobId The ID of the job to abort
244
- */
245
- abort(jobId: unknown): Promise<void>;
246
- /**
247
- * Handles the abort of a job
248
- * @param jobId The ID of the job to abort
249
- */
250
- protected handleAbort(jobId: unknown): Promise<void>;
251
- /**
252
- * Processes a job and handles its lifecycle including runAttempts and error handling
253
- */
254
- protected processSingleJob(job: Job<Input, Output>): Promise<void>;
255
- /**
256
- * Main job processing loop
257
- */
258
- protected processJobs(): Promise<void>;
259
- protected cleanUpJobs(): Promise<void>;
260
- /**
261
- * Monitors jobs that have progress listeners attached
262
- * Polls for updates to jobs being processed elsewhere
263
- * Only emits events when progress state has changed
264
- */
265
- protected monitorJobs(): Promise<void>;
266
- /**
267
- * Fixes stuck jobs when the server restarts
268
- */
269
- protected fixupJobs(): Promise<void>;
270
- }
271
- export {};
272
- //# sourceMappingURL=JobQueue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"JobQueue.d.ts","sourceRoot":"","sources":["../../src/job/JobQueue.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,aAAa,EACb,gBAAgB,EAEjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAgC,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAe,MAAM,qBAAqB,CA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CAAC,OAAO,EAAE,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC;IA+BtF;;;;OAIG;IACI,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC;cA+B/D,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,EAAE,IAAI;cAkBvD,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC;cAqBlC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ;cAgChD,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM;IAiCpE;;;OAGG;IACU,KAAK,CAAC,KAAK,EAAE,OAAO;IAoBjC;;;OAGG;cACa,WAAW,CAAC,KAAK,EAAE,OAAO;IAgB1C;;OAEG;cACa,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAuCxE;;OAEG;cACa,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;cAuB5B,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB5C;;;;OAIG;cACa,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAqD5C;;OAEG;cACa,SAAS;CAgB1B"}
@@ -1,32 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { ILimiter, RateLimiterWithBackoffOptions } from "./ILimiter";
7
- export declare const MEMORY_JOB_RATE_LIMITER: import("@workglow/util").ServiceToken<ILimiter>;
8
- /**
9
- * In-memory implementation of a rate limiter.
10
- * Manages request counts and delays to control job execution.
11
- */
12
- export declare class InMemoryRateLimiter implements ILimiter {
13
- private requests;
14
- private nextAvailableTime;
15
- private currentBackoffDelay;
16
- private readonly maxExecutions;
17
- private readonly windowSizeInMilliseconds;
18
- private readonly initialBackoffDelay;
19
- private readonly backoffMultiplier;
20
- private readonly maxBackoffDelay;
21
- constructor({ maxExecutions, windowSizeInSeconds, initialBackoffDelay, backoffMultiplier, maxBackoffDelay, }: RateLimiterWithBackoffOptions);
22
- private removeOldRequests;
23
- private increaseBackoff;
24
- private addJitter;
25
- canProceed(): Promise<boolean>;
26
- recordJobStart(): Promise<void>;
27
- recordJobCompletion(): Promise<void>;
28
- getNextAvailableTime(): Promise<Date>;
29
- setNextAvailableTime(date: Date): Promise<void>;
30
- clear(): Promise<void>;
31
- }
32
- //# sourceMappingURL=InMemoryRateLimiter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InMemoryRateLimiter.d.ts","sourceRoot":"","sources":["../../src/limiter/InMemoryRateLimiter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,QAAQ,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAErE,eAAO,MAAM,uBAAuB,iDAA+D,CAAC;AAEpG;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,QAAQ;IAClD,OAAO,CAAC,QAAQ,CAAc;IAC9B,OAAO,CAAC,iBAAiB,CAAc;IACvC,OAAO,CAAC,mBAAmB,CAAS;IAEpC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAS;IAClD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,EACV,aAAa,EACb,mBAAmB,EACnB,mBAA2B,EAC3B,iBAAqB,EACrB,eAAyB,GAC1B,EAAE,6BAA6B;IAyBhC,OAAO,CAAC,iBAAiB;IAWzB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,SAAS;IAKX,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAiB9B,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAW/B,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAKrC,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAM/C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
@@ -1,53 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { ILimiter, RateLimiterWithBackoffOptions } from "@workglow/job-queue";
7
- import { Pool } from "pg";
8
- export declare const POSTGRES_JOB_RATE_LIMITER: import("@workglow/util").ServiceToken<ILimiter>;
9
- /**
10
- * PostgreSQL implementation of a rate limiter.
11
- * Manages request counts and delays to control job execution.
12
- */
13
- export declare class PostgresRateLimiter implements ILimiter {
14
- protected readonly db: Pool;
15
- private readonly queueName;
16
- private readonly windowSizeInMilliseconds;
17
- private currentBackoffDelay;
18
- constructor(db: Pool, queueName: string, { maxExecutions, windowSizeInSeconds, initialBackoffDelay, backoffMultiplier, maxBackoffDelay, }: RateLimiterWithBackoffOptions);
19
- private readonly maxExecutions;
20
- private readonly initialBackoffDelay;
21
- private readonly backoffMultiplier;
22
- private readonly maxBackoffDelay;
23
- private dbPromise;
24
- private addJitter;
25
- private increaseBackoff;
26
- ensureTableExists(): Promise<void>;
27
- /**
28
- * Clears all rate limit entries for this queue.
29
- */
30
- clear(): Promise<void>;
31
- /**
32
- * Checks if a job can proceed based on rate limiting rules.
33
- * @returns True if the job can proceed, false otherwise
34
- */
35
- canProceed(): Promise<boolean>;
36
- /**
37
- * Records a new job attempt.
38
- * @returns The ID of the added job
39
- */
40
- recordJobStart(): Promise<void>;
41
- recordJobCompletion(): Promise<void>;
42
- /**
43
- * Retrieves the next available time for the specific queue.
44
- * @returns The next available time
45
- */
46
- getNextAvailableTime(): Promise<Date>;
47
- /**
48
- * Sets the next available time for the specific queue.
49
- * @param date - The new next available time
50
- */
51
- setNextAvailableTime(date: Date): Promise<void>;
52
- }
53
- //# sourceMappingURL=PostgresRateLimiter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostgresRateLimiter.d.ts","sourceRoot":"","sources":["../../src/limiter/PostgresRateLimiter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAE9E,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE1B,eAAO,MAAM,yBAAyB,iDAErC,CAAC;AAEF;;;GAGG;AACH,qBAAa,mBAAoB,YAAW,QAAQ;IAKhD,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,IAAI;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAL5B,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAS;IAClD,OAAO,CAAC,mBAAmB,CAAS;gBAGf,EAAE,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EAClC,EACE,aAAa,EACb,mBAAmB,EACnB,mBAA2B,EAC3B,iBAAqB,EACrB,eAAyB,GAC1B,EAAE,6BAA6B;IA2BlC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,SAAS,CAAgB;IAEjC,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,eAAe;IAOV,iBAAiB;IAgB9B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IA0CpC;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B/B,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1C;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IAyC3C;;;OAGG;IACG,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAatD"}
@@ -1,44 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- import { ILimiter, RateLimiterWithBackoffOptions } from "@workglow/job-queue";
7
- import type { Sqlite } from "@workglow/sqlite";
8
- export declare const SQLITE_JOB_RATE_LIMITER: import("@workglow/util").ServiceToken<ILimiter>;
9
- /**
10
- * SQLite implementation of a rate limiter.
11
- * Manages request counts and delays to control job execution.
12
- */
13
- export declare class SqliteRateLimiter implements ILimiter {
14
- private readonly db;
15
- private readonly queueName;
16
- private readonly windowSizeInMilliseconds;
17
- private currentBackoffDelay;
18
- constructor(db: Sqlite.Database, queueName: string, { maxExecutions, windowSizeInSeconds, initialBackoffDelay, backoffMultiplier, maxBackoffDelay, }: RateLimiterWithBackoffOptions);
19
- private readonly maxExecutions;
20
- private readonly initialBackoffDelay;
21
- private readonly backoffMultiplier;
22
- private readonly maxBackoffDelay;
23
- private addJitter;
24
- private increaseBackoff;
25
- ensureTableExists(): this;
26
- /**
27
- * Clears all rate limit entries for this queue.
28
- */
29
- clear(): Promise<void>;
30
- /**
31
- * Checks if a job can proceed based on rate limiting rules.
32
- * @returns True if the job can proceed, false otherwise
33
- */
34
- canProceed(): Promise<boolean>;
35
- /**
36
- * Records a new job attempt.
37
- * @returns The ID of the added job
38
- */
39
- recordJobStart(): Promise<void>;
40
- recordJobCompletion(): Promise<void>;
41
- getNextAvailableTime(): Promise<Date>;
42
- setNextAvailableTime(date: Date): Promise<void>;
43
- }
44
- //# sourceMappingURL=SqliteRateLimiter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SqliteRateLimiter.d.ts","sourceRoot":"","sources":["../../src/limiter/SqliteRateLimiter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG/C,eAAO,MAAM,uBAAuB,iDAA+D,CAAC;AAEpG;;;GAGG;AACH,qBAAa,iBAAkB,YAAW,QAAQ;IAChD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAkB;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAS;IAClD,OAAO,CAAC,mBAAmB,CAAS;gBAGlC,EAAE,EAAE,MAAM,CAAC,QAAQ,EACnB,SAAS,EAAE,MAAM,EACjB,EACE,aAAa,EACb,mBAAmB,EACnB,mBAA2B,EAC3B,iBAAqB,EACrB,eAAyB,GAC1B,EAAE,6BAA6B;IA6BlC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,eAAe;IAOhB,iBAAiB;IAiBxB;;OAEG;IACG,KAAK;IASX;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAqCpC;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAuB/B,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC,oBAAoB,IAAI,OAAO,CA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