@orieljs/queue 0.1.0-alpha.14 → 0.1.0-alpha.16
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/dist/index.d.ts +89 -11
- package/dist/index.js +283 -75
- package/dist/index.js.map +1 -1
- package/package.json +16 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrielError, ModelNotFoundError, Job, ClassRegistry, Class, ModelInstance, QueuePayload, Container, QueueJob, Queue as Queue$1, QueueManager as QueueManager$1, DatabaseConnection, FailedJobProvider, FailedJob, ConfigRepository, Batch as Batch$1, BatchRepository, PendingBatchOptions, Application, ConsoleKernel } from '@orieljs/contracts';
|
|
1
|
+
import { OrielError, ModelNotFoundError, Job, ClassRegistry, Class, ModelInstance, QueuePayload, Container, QueueJob, Queue as Queue$1, QueueManager as QueueManager$1, QueueJobEvent, QueueJobFailedEvent, DatabaseConnection, FailedJobProvider, FailedJob, ConfigRepository, Batch as Batch$1, BatchRepository, PendingBatchOptions, Application, ConsoleKernel } from '@orieljs/contracts';
|
|
2
2
|
import { Redis } from 'ioredis';
|
|
3
3
|
import { SpawnOptions, ChildProcess } from 'node:child_process';
|
|
4
4
|
import * as _orieljs_support from '@orieljs/support';
|
|
@@ -142,8 +142,14 @@ declare class CallQueuedHandler {
|
|
|
142
142
|
call(job: BaseJob): Promise<void>;
|
|
143
143
|
/** Called by BaseJob.fail() after the job was deleted. */
|
|
144
144
|
failed(job: BaseJob, error: unknown): Promise<void>;
|
|
145
|
-
/**
|
|
146
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Dispatches a callback job (chain catch, batch then/catch/finally) through the Bus, or runs it inline. It goes to
|
|
147
|
+
* `target`'s connection and queue (the chain's or the batch's) unless it names its own.
|
|
148
|
+
*/
|
|
149
|
+
dispatchCallback(callback: Job, target?: {
|
|
150
|
+
connection?: string;
|
|
151
|
+
queue?: string;
|
|
152
|
+
}): Promise<void>;
|
|
147
153
|
private handleModelNotFound;
|
|
148
154
|
private dispatchThroughMiddleware;
|
|
149
155
|
private dispatchNextJobInChain;
|
|
@@ -190,7 +196,8 @@ declare abstract class BaseJob implements QueueJob {
|
|
|
190
196
|
fire(): Promise<void>;
|
|
191
197
|
/**
|
|
192
198
|
* Marks the job as failed, deletes it, runs the handler's failure bookkeeping (unique lock, batch, chain catch,
|
|
193
|
-
* the job's failed() hook)
|
|
199
|
+
* the job's failed() hook), stores it with the FailedJobProvider and dispatches JobFailed. A job that was already
|
|
200
|
+
* deleted is ignored.
|
|
194
201
|
*/
|
|
195
202
|
fail(error?: unknown): Promise<void>;
|
|
196
203
|
}
|
|
@@ -227,20 +234,65 @@ declare class WithoutOverlapping {
|
|
|
227
234
|
handle(job: Job, next: (job: Job) => Promise<unknown>): Promise<unknown>;
|
|
228
235
|
}
|
|
229
236
|
|
|
237
|
+
/** Laravel's JobQueued: a job was pushed onto a queue (the sync queue runs it instead, and dispatches none). */
|
|
238
|
+
declare class JobQueued {
|
|
239
|
+
readonly connectionName: string;
|
|
240
|
+
readonly queue: string;
|
|
241
|
+
readonly id: string;
|
|
242
|
+
readonly job: Job;
|
|
243
|
+
readonly payload: QueuePayload;
|
|
244
|
+
readonly delay: number | undefined;
|
|
245
|
+
constructor(connectionName: string, queue: string, id: string, job: Job, payload: QueuePayload, delay: number | undefined);
|
|
246
|
+
}
|
|
247
|
+
/** Laravel's JobProcessing: a worker (or the sync queue) is about to run a job. */
|
|
248
|
+
declare class JobProcessing {
|
|
249
|
+
readonly connectionName: string;
|
|
250
|
+
readonly job: QueueJob;
|
|
251
|
+
constructor(connectionName: string, job: QueueJob);
|
|
252
|
+
}
|
|
253
|
+
/** Laravel's JobProcessed: a job ran without throwing. */
|
|
254
|
+
declare class JobProcessed {
|
|
255
|
+
readonly connectionName: string;
|
|
256
|
+
readonly job: QueueJob;
|
|
257
|
+
constructor(connectionName: string, job: QueueJob);
|
|
258
|
+
}
|
|
259
|
+
/** Laravel's JobFailed: a job failed for good, with no attempts left (or was failed on purpose). */
|
|
260
|
+
declare class JobFailed {
|
|
261
|
+
readonly connectionName: string;
|
|
262
|
+
readonly job: QueueJob;
|
|
263
|
+
readonly exception: unknown;
|
|
264
|
+
constructor(connectionName: string, job: QueueJob, exception: unknown);
|
|
265
|
+
}
|
|
266
|
+
|
|
230
267
|
/** Shared driver behaviour (Laravel's Illuminate\Queue\Queue): payload creation, queue names, the job context. */
|
|
231
268
|
declare abstract class QueueBase implements Queue$1 {
|
|
232
269
|
protected readonly container: Container;
|
|
233
270
|
protected readonly defaultQueue: string;
|
|
234
271
|
protected connectionName: string;
|
|
272
|
+
/** `queue.connections.<name>.after_commit`: work dispatched inside a transaction waits for its commit. */
|
|
273
|
+
protected dispatchAfterCommit: boolean;
|
|
235
274
|
protected readonly handler: CallQueuedHandler;
|
|
236
275
|
constructor(container: Container, defaultQueue?: string);
|
|
237
276
|
setConnectionName(name: string): this;
|
|
238
277
|
getConnectionName(): string;
|
|
278
|
+
setDispatchAfterCommit(value: boolean): this;
|
|
239
279
|
/** The queue name to use: the given one, else the connection's default. */
|
|
240
280
|
getQueue(queue?: string): string;
|
|
241
281
|
createPayload(job: Job): QueueJobPayload;
|
|
242
282
|
push(job: Job, queue?: string): Promise<string>;
|
|
243
283
|
later(delaySeconds: number, job: Job, queue?: string): Promise<string>;
|
|
284
|
+
/** Waits for the push, then dispatches JobQueued with its id. */
|
|
285
|
+
private pushed;
|
|
286
|
+
/** Laravel's raiseJobQueuedEvent(). */
|
|
287
|
+
protected raiseJobQueued(queue: string, id: string, job: Job, payload: QueuePayload, delay: number | undefined): Promise<void>;
|
|
288
|
+
/** The job's own `afterCommit`, else the connection's `after_commit`. */
|
|
289
|
+
protected shouldDispatchAfterCommit(job: Job): boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Laravel's enqueueUsing(): pushes now, or, for a job that waits for the commit, once the database transaction open
|
|
292
|
+
* here commits (resolving '' meanwhile). The payload is made first, so a job that can't be queued fails at dispatch.
|
|
293
|
+
* A rollback drops the push and frees a unique job's lock, as does a push that fails after the commit.
|
|
294
|
+
*/
|
|
295
|
+
protected enqueue(job: Job, push: () => Promise<string>): Promise<string>;
|
|
244
296
|
abstract pushRaw(payload: QueuePayload, queue?: string, delaySeconds?: number): Promise<string>;
|
|
245
297
|
abstract pop(queue?: string): Promise<QueueJob | undefined>;
|
|
246
298
|
abstract size(queue?: string): Promise<number>;
|
|
@@ -262,9 +314,12 @@ declare abstract class QueueBase implements Queue$1 {
|
|
|
262
314
|
/**
|
|
263
315
|
* Runs jobs immediately, in the dispatching process (delays are ignored). The payload is still built and the job
|
|
264
316
|
* restored from it, so sync behaves like a real worker. A failure is stored with the FailedJobProvider and rethrown.
|
|
317
|
+
* As Laravel 11's, it dispatches JobProcessing, JobProcessed and JobFailed, and no JobQueued.
|
|
265
318
|
*/
|
|
266
319
|
declare class SyncQueue extends QueueBase {
|
|
267
320
|
pushRaw(payload: QueuePayload, queue?: string): Promise<string>;
|
|
321
|
+
/** The job has run already: nothing was queued. */
|
|
322
|
+
protected raiseJobQueued(_queue: string, _id: string, _job: Job, _payload: QueuePayload, _delay: number | undefined): Promise<void>;
|
|
268
323
|
pop(): Promise<QueueJob | undefined>;
|
|
269
324
|
size(): Promise<number>;
|
|
270
325
|
clear(): Promise<number>;
|
|
@@ -293,6 +348,9 @@ declare class QueueManager implements QueueManager$1 {
|
|
|
293
348
|
* exported `BaseJob` subclasses (or subclasses of `BaseJob`): the Worker relies on their methods.
|
|
294
349
|
*/
|
|
295
350
|
extend(driver: string, factory: (config: ConnectionConfig) => Queue$1): void;
|
|
351
|
+
before(callback: (event: QueueJobEvent) => unknown): void;
|
|
352
|
+
after(callback: (event: QueueJobEvent) => unknown): void;
|
|
353
|
+
failing(callback: (event: QueueJobFailedEvent) => unknown): void;
|
|
296
354
|
getDefaultDriver(): string;
|
|
297
355
|
setDefaultDriver(name: string): void;
|
|
298
356
|
getConnectionConfig(name: string): ConnectionConfig | undefined;
|
|
@@ -430,8 +488,12 @@ interface RedisConnectionConfig {
|
|
|
430
488
|
url?: string;
|
|
431
489
|
[option: string]: unknown;
|
|
432
490
|
}
|
|
433
|
-
/**
|
|
434
|
-
|
|
491
|
+
/**
|
|
492
|
+
* An ioredis client. With a URL, the other options (such as `db`) apply where the URL doesn't set them. ioredis is an
|
|
493
|
+
* optional package, imported here, when the connection is first used: without it, this throws MissingPackageError.
|
|
494
|
+
* A prebuilt client imports nothing.
|
|
495
|
+
*/
|
|
496
|
+
declare function makeRedisClient(config: RedisConnectionConfig): Promise<Redis>;
|
|
435
497
|
/**
|
|
436
498
|
* The client config for a redis queue connection. An inline `client` or `url` wins; otherwise, as in Laravel, the
|
|
437
499
|
* `database.redis.<connection ?? 'default'>` entry (merged by Database). The connection's own inline ioredis
|
|
@@ -443,8 +505,9 @@ declare class RedisQueue extends QueueBase {
|
|
|
443
505
|
private readonly connect;
|
|
444
506
|
private client;
|
|
445
507
|
private readonly retryAfter;
|
|
446
|
-
|
|
447
|
-
|
|
508
|
+
/** `connect` gives the client (or a promise of it), at the queue's first command. */
|
|
509
|
+
constructor(container: Container, connect: () => Redis | Promise<Redis>, options?: RedisQueueOptions);
|
|
510
|
+
redis(): Promise<Redis>;
|
|
448
511
|
/** The list key for a queue name: `queues:<name>`. */
|
|
449
512
|
key(queue?: string): string;
|
|
450
513
|
pushRaw(payload: QueuePayload, queue?: string, delaySeconds?: number): Promise<string>;
|
|
@@ -604,8 +667,11 @@ declare class Worker {
|
|
|
604
667
|
listenForSignals(): () => void;
|
|
605
668
|
/** F2: installs the process-wide unhandledRejection guard; returns a function that removes it. */
|
|
606
669
|
private guardUnhandledRejections;
|
|
607
|
-
/**
|
|
608
|
-
|
|
670
|
+
/**
|
|
671
|
+
* Processes one job: max-attempts check, fire (with timeout), and failure handling. Dispatches JobProcessing first
|
|
672
|
+
* and JobProcessed once the job has run without failing (BaseJob.fail() dispatches JobFailed).
|
|
673
|
+
*/
|
|
674
|
+
process(connectionName: string, job: QueueJob, options: WorkerOptions): Promise<void>;
|
|
609
675
|
sleep(seconds: number): Promise<void>;
|
|
610
676
|
/** Runs one job in its own scope. Nothing it throws escapes: an error from the failure handling itself (a failed()
|
|
611
677
|
* hook, the failed-job provider, a release) is reported like any other, as Laravel's Worker::runJob does. */
|
|
@@ -712,6 +778,18 @@ declare const WORKER_DISCOVERY_DIRECTORIES: readonly ["Events", "Listeners", "Ma
|
|
|
712
778
|
declare function discoverClasses(directory: string, registry: ClassRegistry, filter?: (cls: Class<unknown>) => boolean): Promise<string[]>;
|
|
713
779
|
/** Registers the exported classes under `directory` that have a handle() method (app/Jobs). */
|
|
714
780
|
declare function discoverJobs(directory: string, registry: ClassRegistry): Promise<string[]>;
|
|
781
|
+
/**
|
|
782
|
+
* Registers the app's classes a worker may have to restore: those exported under app/Jobs (with a handle() method) and
|
|
783
|
+
* under the WORKER_DISCOVERY_DIRECTORIES. A class keeps its bare name unless another class found there, not yet named,
|
|
784
|
+
* has it too; then each is named by its folder (`Events.OrderShipped`, `Mail.OrderShipped`, `Mail.Orders.Shipped`).
|
|
785
|
+
* A class registered explicitly keeps that name. The worker and the dispatching process both run this, so they agree.
|
|
786
|
+
*/
|
|
787
|
+
declare function registerAppClasses(appPath: string, registry: ClassRegistry): Promise<void>;
|
|
788
|
+
/**
|
|
789
|
+
* Before a process builds its first payload: its app classes get the names a worker gives them (registerAppClasses).
|
|
790
|
+
* Runs once per registry; a container with no Application (a bare test) has no app folders to read.
|
|
791
|
+
*/
|
|
792
|
+
declare function ensureAppClasses(container: Container): Promise<void>;
|
|
715
793
|
|
|
716
794
|
interface QueueCommandContext {
|
|
717
795
|
app: Pick<Application, 'isProduction' | 'appPath' | 'basePath'>;
|
|
@@ -742,4 +820,4 @@ declare class QueueServiceProvider extends ServiceProvider {
|
|
|
742
820
|
boot(): void;
|
|
743
821
|
}
|
|
744
822
|
|
|
745
|
-
export { BaseJob, Batch, type BatchAttributes, CHAIN, CallQueuedHandler, type ChainSpec, type ConnectionConfig, DatabaseBatchRepository, DatabaseFailedJobProvider, DatabaseJob, type DatabaseJobRecord, DatabaseQueue, type DatabaseQueueOptions, type Encoded, JOBS_TABLE_MIGRATION, JobClassNotFoundError, type JobContext, type JobMiddleware, JobSerializationError, Listener, type ListenerConfig, type ListenerOptions, type ListenerOutput, ManuallyFailedError, MaxAttemptsExceededError, MissingModelError, NullFailedJobProvider, NullQueue, QUEUE_JOB, Queue, QueueBase, type QueueCommandContext, QueueError, type QueueJobPayload, QueueManager, QueueServiceProvider, RESTART_CACHE_KEY, type RedisConnectionConfig, RedisJob, RedisQueue, type RedisQueueOptions, type SpawnWorker, type StoredBatchOptions, SyncJob, SyncQueue, TimeoutExceededError, UNIQUE_LOCK, type UniqueLockSpec, UnknownQueueConnectionError, UnknownQueueDriverError, WORKER_DISCOVERY_DIRECTORIES, WithoutOverlapping, Worker, type WorkerListener, type WorkerOptions, classNameOf, createPayload, decodePayload, defaultListenerOptions, defaultWorkerOptions, describeError, discoverClasses, discoverJobs, encodePayload, formatTimestamp, isModel, listenerOptionsFrom, makeFailedJobProvider, makeRedisClient, normalizeBackoff, queueConfigDefaults, registerQueueCommands, resolveRedisConfig, restoreJob, restoreValue, serializeValue, workerOptionsFrom };
|
|
823
|
+
export { BaseJob, Batch, type BatchAttributes, CHAIN, CallQueuedHandler, type ChainSpec, type ConnectionConfig, DatabaseBatchRepository, DatabaseFailedJobProvider, DatabaseJob, type DatabaseJobRecord, DatabaseQueue, type DatabaseQueueOptions, type Encoded, JOBS_TABLE_MIGRATION, JobClassNotFoundError, type JobContext, JobFailed, type JobMiddleware, JobProcessed, JobProcessing, JobQueued, JobSerializationError, Listener, type ListenerConfig, type ListenerOptions, type ListenerOutput, ManuallyFailedError, MaxAttemptsExceededError, MissingModelError, NullFailedJobProvider, NullQueue, QUEUE_JOB, Queue, QueueBase, type QueueCommandContext, QueueError, type QueueJobPayload, QueueManager, QueueServiceProvider, RESTART_CACHE_KEY, type RedisConnectionConfig, RedisJob, RedisQueue, type RedisQueueOptions, type SpawnWorker, type StoredBatchOptions, SyncJob, SyncQueue, TimeoutExceededError, UNIQUE_LOCK, type UniqueLockSpec, UnknownQueueConnectionError, UnknownQueueDriverError, WORKER_DISCOVERY_DIRECTORIES, WithoutOverlapping, Worker, type WorkerListener, type WorkerOptions, classNameOf, createPayload, decodePayload, defaultListenerOptions, defaultWorkerOptions, describeError, discoverClasses, discoverJobs, encodePayload, ensureAppClasses, formatTimestamp, isModel, listenerOptionsFrom, makeFailedJobProvider, makeRedisClient, normalizeBackoff, queueConfigDefaults, registerAppClasses, registerQueueCommands, resolveRedisConfig, restoreJob, restoreValue, serializeValue, workerOptionsFrom };
|