@nicnocquee/dataqueue 1.31.0 → 1.32.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/dist/index.cjs +2418 -1936
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +151 -16
- package/dist/index.d.ts +151 -16
- package/dist/index.js +2418 -1936
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/backend.ts +70 -4
- package/src/backends/postgres.ts +345 -29
- package/src/backends/redis-scripts.ts +197 -22
- package/src/backends/redis.test.ts +621 -0
- package/src/backends/redis.ts +400 -21
- package/src/index.ts +12 -29
- package/src/processor.ts +14 -93
- package/src/queue.test.ts +29 -0
- package/src/queue.ts +19 -251
- package/src/types.ts +28 -10
package/dist/index.d.cts
CHANGED
|
@@ -449,6 +449,23 @@ interface PostgresJobQueueConfig {
|
|
|
449
449
|
user?: string;
|
|
450
450
|
password?: string;
|
|
451
451
|
ssl?: DatabaseSSLConfig;
|
|
452
|
+
/**
|
|
453
|
+
* Maximum number of clients in the pool (default: 10).
|
|
454
|
+
* Increase when running multiple processors in the same process.
|
|
455
|
+
*/
|
|
456
|
+
max?: number;
|
|
457
|
+
/**
|
|
458
|
+
* Minimum number of idle clients in the pool (default: 0).
|
|
459
|
+
*/
|
|
460
|
+
min?: number;
|
|
461
|
+
/**
|
|
462
|
+
* Milliseconds a client must sit idle before being closed (default: 10000).
|
|
463
|
+
*/
|
|
464
|
+
idleTimeoutMillis?: number;
|
|
465
|
+
/**
|
|
466
|
+
* Milliseconds to wait for a connection before throwing (default: 0, no timeout).
|
|
467
|
+
*/
|
|
468
|
+
connectionTimeoutMillis?: number;
|
|
452
469
|
};
|
|
453
470
|
verbose?: boolean;
|
|
454
471
|
}
|
|
@@ -626,12 +643,18 @@ interface JobQueue<PayloadMap> {
|
|
|
626
643
|
retryJob: (jobId: number) => Promise<void>;
|
|
627
644
|
/**
|
|
628
645
|
* Cleanup jobs that are older than the specified number of days.
|
|
646
|
+
* Deletes in batches for scale safety.
|
|
647
|
+
* @param daysToKeep - Number of days to retain completed jobs (default 30).
|
|
648
|
+
* @param batchSize - Number of rows to delete per batch (default 1000 for PostgreSQL, 200 for Redis).
|
|
629
649
|
*/
|
|
630
|
-
cleanupOldJobs: (daysToKeep?: number) => Promise<number>;
|
|
650
|
+
cleanupOldJobs: (daysToKeep?: number, batchSize?: number) => Promise<number>;
|
|
631
651
|
/**
|
|
632
652
|
* Cleanup job events that are older than the specified number of days.
|
|
653
|
+
* Deletes in batches for scale safety.
|
|
654
|
+
* @param daysToKeep - Number of days to retain events (default 30).
|
|
655
|
+
* @param batchSize - Number of rows to delete per batch (default 1000).
|
|
633
656
|
*/
|
|
634
|
-
cleanupOldJobEvents: (daysToKeep?: number) => Promise<number>;
|
|
657
|
+
cleanupOldJobEvents: (daysToKeep?: number, batchSize?: number) => Promise<number>;
|
|
635
658
|
/**
|
|
636
659
|
* Cancel a job given its ID.
|
|
637
660
|
* - This will set the job status to 'cancelled' and clear the locked_at and locked_by.
|
|
@@ -718,8 +741,6 @@ interface JobQueue<PayloadMap> {
|
|
|
718
741
|
* Tokens can be completed externally to resume a waiting job.
|
|
719
742
|
* Can be called outside of handlers (e.g., from an API route).
|
|
720
743
|
*
|
|
721
|
-
* **PostgreSQL backend only.** Throws if the backend is Redis.
|
|
722
|
-
*
|
|
723
744
|
* @param options - Optional token configuration (timeout, tags).
|
|
724
745
|
* @returns A token object with `id`.
|
|
725
746
|
*/
|
|
@@ -728,8 +749,6 @@ interface JobQueue<PayloadMap> {
|
|
|
728
749
|
* Complete a waitpoint token, resuming the associated waiting job.
|
|
729
750
|
* Can be called from anywhere (API routes, external services, etc.).
|
|
730
751
|
*
|
|
731
|
-
* **PostgreSQL backend only.** Throws if the backend is Redis.
|
|
732
|
-
*
|
|
733
752
|
* @param tokenId - The ID of the token to complete.
|
|
734
753
|
* @param data - Optional data to pass to the waiting handler.
|
|
735
754
|
*/
|
|
@@ -737,8 +756,6 @@ interface JobQueue<PayloadMap> {
|
|
|
737
756
|
/**
|
|
738
757
|
* Retrieve a waitpoint token by its ID.
|
|
739
758
|
*
|
|
740
|
-
* **PostgreSQL backend only.** Throws if the backend is Redis.
|
|
741
|
-
*
|
|
742
759
|
* @param tokenId - The ID of the token to retrieve.
|
|
743
760
|
* @returns The token record, or null if not found.
|
|
744
761
|
*/
|
|
@@ -747,8 +764,6 @@ interface JobQueue<PayloadMap> {
|
|
|
747
764
|
* Expire timed-out waitpoint tokens and resume their associated jobs.
|
|
748
765
|
* Call this periodically (e.g., alongside `reclaimStuckJobs`).
|
|
749
766
|
*
|
|
750
|
-
* **PostgreSQL backend only.** Throws if the backend is Redis.
|
|
751
|
-
*
|
|
752
767
|
* @returns The number of tokens that were expired.
|
|
753
768
|
*/
|
|
754
769
|
expireTimedOutTokens: () => Promise<number>;
|
|
@@ -906,10 +921,10 @@ interface QueueBackend {
|
|
|
906
921
|
editJob(jobId: number, updates: JobUpdates): Promise<void>;
|
|
907
922
|
/** Edit all pending jobs matching filters. Returns count. */
|
|
908
923
|
editAllPendingJobs(filters: JobFilters | undefined, updates: JobUpdates): Promise<number>;
|
|
909
|
-
/** Delete completed jobs older than N days. Returns count deleted. */
|
|
910
|
-
cleanupOldJobs(daysToKeep?: number): Promise<number>;
|
|
911
|
-
/** Delete job events older than N days. Returns count deleted. */
|
|
912
|
-
cleanupOldJobEvents(daysToKeep?: number): Promise<number>;
|
|
924
|
+
/** Delete completed jobs older than N days. Deletes in batches for scale safety. Returns count deleted. */
|
|
925
|
+
cleanupOldJobs(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
926
|
+
/** Delete job events older than N days. Deletes in batches for scale safety. Returns count deleted. */
|
|
927
|
+
cleanupOldJobEvents(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
913
928
|
/** Reclaim jobs stuck in 'processing' for too long. Returns count. */
|
|
914
929
|
reclaimStuckJobs(maxProcessingTimeMinutes?: number): Promise<number>;
|
|
915
930
|
/** Update the progress percentage (0-100) for a job. */
|
|
@@ -944,6 +959,58 @@ interface QueueBackend {
|
|
|
944
959
|
* Sets lastEnqueuedAt, lastJobId, and advances nextRunAt.
|
|
945
960
|
*/
|
|
946
961
|
updateCronScheduleAfterEnqueue(id: number, lastEnqueuedAt: Date, lastJobId: number, nextRunAt: Date | null): Promise<void>;
|
|
962
|
+
/**
|
|
963
|
+
* Transition a job from 'processing' to 'waiting' status.
|
|
964
|
+
* Persists step data so the handler can resume from where it left off.
|
|
965
|
+
*
|
|
966
|
+
* @param jobId - The job to pause.
|
|
967
|
+
* @param options - Wait configuration including optional waitUntil date, token ID, and step data.
|
|
968
|
+
*/
|
|
969
|
+
waitJob(jobId: number, options: {
|
|
970
|
+
waitUntil?: Date;
|
|
971
|
+
waitTokenId?: string;
|
|
972
|
+
stepData: Record<string, any>;
|
|
973
|
+
}): Promise<void>;
|
|
974
|
+
/**
|
|
975
|
+
* Persist step data for a job. Called after each `ctx.run()` step completes
|
|
976
|
+
* to save intermediate progress. Best-effort: should not throw.
|
|
977
|
+
*
|
|
978
|
+
* @param jobId - The job to update.
|
|
979
|
+
* @param stepData - The step data to persist.
|
|
980
|
+
*/
|
|
981
|
+
updateStepData(jobId: number, stepData: Record<string, any>): Promise<void>;
|
|
982
|
+
/**
|
|
983
|
+
* Create a waitpoint token that can pause a job until an external signal completes it.
|
|
984
|
+
*
|
|
985
|
+
* @param jobId - The job ID to associate with the token (null if created outside a handler).
|
|
986
|
+
* @param options - Optional timeout string (e.g. '10m', '1h') and tags.
|
|
987
|
+
* @returns The created waitpoint with its unique ID.
|
|
988
|
+
*/
|
|
989
|
+
createWaitpoint(jobId: number | null, options?: CreateTokenOptions): Promise<{
|
|
990
|
+
id: string;
|
|
991
|
+
}>;
|
|
992
|
+
/**
|
|
993
|
+
* Complete a waitpoint token, optionally providing output data.
|
|
994
|
+
* Moves the associated job from 'waiting' back to 'pending' so it gets picked up.
|
|
995
|
+
*
|
|
996
|
+
* @param tokenId - The waitpoint token ID to complete.
|
|
997
|
+
* @param data - Optional data to pass to the waiting handler.
|
|
998
|
+
*/
|
|
999
|
+
completeWaitpoint(tokenId: string, data?: any): Promise<void>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Retrieve a waitpoint token by its ID.
|
|
1002
|
+
*
|
|
1003
|
+
* @param tokenId - The waitpoint token ID to look up.
|
|
1004
|
+
* @returns The waitpoint record, or null if not found.
|
|
1005
|
+
*/
|
|
1006
|
+
getWaitpoint(tokenId: string): Promise<WaitpointRecord | null>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Expire timed-out waitpoint tokens and move their associated jobs back to 'pending'.
|
|
1009
|
+
* Should be called periodically (e.g., alongside reclaimStuckJobs).
|
|
1010
|
+
*
|
|
1011
|
+
* @returns The number of tokens that were expired.
|
|
1012
|
+
*/
|
|
1013
|
+
expireTimedOutWaitpoints(): Promise<number>;
|
|
947
1014
|
/** Set a pending reason for unpicked jobs of a given type. */
|
|
948
1015
|
setPendingReasonForUnpickedJobs(reason: string, jobType?: string | string[]): Promise<void>;
|
|
949
1016
|
}
|
|
@@ -971,8 +1038,26 @@ declare class PostgresBackend implements QueueBackend {
|
|
|
971
1038
|
cancelAllUpcomingJobs(filters?: JobFilters): Promise<number>;
|
|
972
1039
|
editJob(jobId: number, updates: JobUpdates): Promise<void>;
|
|
973
1040
|
editAllPendingJobs(filters: JobFilters | undefined, updates: JobUpdates): Promise<number>;
|
|
974
|
-
|
|
975
|
-
|
|
1041
|
+
/**
|
|
1042
|
+
* Delete completed jobs older than the given number of days.
|
|
1043
|
+
* Deletes in batches of 1000 to avoid long-running transactions
|
|
1044
|
+
* and excessive WAL bloat at scale.
|
|
1045
|
+
*
|
|
1046
|
+
* @param daysToKeep - Number of days to retain completed jobs (default 30).
|
|
1047
|
+
* @param batchSize - Number of rows to delete per batch (default 1000).
|
|
1048
|
+
* @returns Total number of deleted jobs.
|
|
1049
|
+
*/
|
|
1050
|
+
cleanupOldJobs(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
1051
|
+
/**
|
|
1052
|
+
* Delete job events older than the given number of days.
|
|
1053
|
+
* Deletes in batches of 1000 to avoid long-running transactions
|
|
1054
|
+
* and excessive WAL bloat at scale.
|
|
1055
|
+
*
|
|
1056
|
+
* @param daysToKeep - Number of days to retain events (default 30).
|
|
1057
|
+
* @param batchSize - Number of rows to delete per batch (default 1000).
|
|
1058
|
+
* @returns Total number of deleted events.
|
|
1059
|
+
*/
|
|
1060
|
+
cleanupOldJobEvents(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
976
1061
|
reclaimStuckJobs(maxProcessingTimeMinutes?: number): Promise<number>;
|
|
977
1062
|
/**
|
|
978
1063
|
* Batch-insert multiple job events in a single query.
|
|
@@ -1005,6 +1090,56 @@ declare class PostgresBackend implements QueueBackend {
|
|
|
1005
1090
|
* Sets lastEnqueuedAt, lastJobId, and advances nextRunAt.
|
|
1006
1091
|
*/
|
|
1007
1092
|
updateCronScheduleAfterEnqueue(id: number, lastEnqueuedAt: Date, lastJobId: number, nextRunAt: Date | null): Promise<void>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Transition a job from 'processing' to 'waiting' status.
|
|
1095
|
+
* Persists step data so the handler can resume from where it left off.
|
|
1096
|
+
*
|
|
1097
|
+
* @param jobId - The job to pause.
|
|
1098
|
+
* @param options - Wait configuration including optional waitUntil date, token ID, and step data.
|
|
1099
|
+
*/
|
|
1100
|
+
waitJob(jobId: number, options: {
|
|
1101
|
+
waitUntil?: Date;
|
|
1102
|
+
waitTokenId?: string;
|
|
1103
|
+
stepData: Record<string, any>;
|
|
1104
|
+
}): Promise<void>;
|
|
1105
|
+
/**
|
|
1106
|
+
* Persist step data for a job. Called after each ctx.run() step completes.
|
|
1107
|
+
* Best-effort: does not throw to avoid killing the running handler.
|
|
1108
|
+
*
|
|
1109
|
+
* @param jobId - The job to update.
|
|
1110
|
+
* @param stepData - The step data to persist.
|
|
1111
|
+
*/
|
|
1112
|
+
updateStepData(jobId: number, stepData: Record<string, any>): Promise<void>;
|
|
1113
|
+
/**
|
|
1114
|
+
* Create a waitpoint token in the database.
|
|
1115
|
+
*
|
|
1116
|
+
* @param jobId - The job ID to associate with the token (null if created outside a handler).
|
|
1117
|
+
* @param options - Optional timeout string (e.g. '10m', '1h') and tags.
|
|
1118
|
+
* @returns The created waitpoint with its unique ID.
|
|
1119
|
+
*/
|
|
1120
|
+
createWaitpoint(jobId: number | null, options?: CreateTokenOptions): Promise<{
|
|
1121
|
+
id: string;
|
|
1122
|
+
}>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Complete a waitpoint token and move the associated job back to 'pending'.
|
|
1125
|
+
*
|
|
1126
|
+
* @param tokenId - The waitpoint token ID to complete.
|
|
1127
|
+
* @param data - Optional data to pass to the waiting handler.
|
|
1128
|
+
*/
|
|
1129
|
+
completeWaitpoint(tokenId: string, data?: any): Promise<void>;
|
|
1130
|
+
/**
|
|
1131
|
+
* Retrieve a waitpoint token by its ID.
|
|
1132
|
+
*
|
|
1133
|
+
* @param tokenId - The waitpoint token ID to look up.
|
|
1134
|
+
* @returns The waitpoint record, or null if not found.
|
|
1135
|
+
*/
|
|
1136
|
+
getWaitpoint(tokenId: string): Promise<WaitpointRecord | null>;
|
|
1137
|
+
/**
|
|
1138
|
+
* Expire timed-out waitpoint tokens and move their associated jobs back to 'pending'.
|
|
1139
|
+
*
|
|
1140
|
+
* @returns The number of tokens that were expired.
|
|
1141
|
+
*/
|
|
1142
|
+
expireTimedOutWaitpoints(): Promise<number>;
|
|
1008
1143
|
setPendingReasonForUnpickedJobs(reason: string, jobType?: string | string[]): Promise<void>;
|
|
1009
1144
|
}
|
|
1010
1145
|
|
package/dist/index.d.ts
CHANGED
|
@@ -449,6 +449,23 @@ interface PostgresJobQueueConfig {
|
|
|
449
449
|
user?: string;
|
|
450
450
|
password?: string;
|
|
451
451
|
ssl?: DatabaseSSLConfig;
|
|
452
|
+
/**
|
|
453
|
+
* Maximum number of clients in the pool (default: 10).
|
|
454
|
+
* Increase when running multiple processors in the same process.
|
|
455
|
+
*/
|
|
456
|
+
max?: number;
|
|
457
|
+
/**
|
|
458
|
+
* Minimum number of idle clients in the pool (default: 0).
|
|
459
|
+
*/
|
|
460
|
+
min?: number;
|
|
461
|
+
/**
|
|
462
|
+
* Milliseconds a client must sit idle before being closed (default: 10000).
|
|
463
|
+
*/
|
|
464
|
+
idleTimeoutMillis?: number;
|
|
465
|
+
/**
|
|
466
|
+
* Milliseconds to wait for a connection before throwing (default: 0, no timeout).
|
|
467
|
+
*/
|
|
468
|
+
connectionTimeoutMillis?: number;
|
|
452
469
|
};
|
|
453
470
|
verbose?: boolean;
|
|
454
471
|
}
|
|
@@ -626,12 +643,18 @@ interface JobQueue<PayloadMap> {
|
|
|
626
643
|
retryJob: (jobId: number) => Promise<void>;
|
|
627
644
|
/**
|
|
628
645
|
* Cleanup jobs that are older than the specified number of days.
|
|
646
|
+
* Deletes in batches for scale safety.
|
|
647
|
+
* @param daysToKeep - Number of days to retain completed jobs (default 30).
|
|
648
|
+
* @param batchSize - Number of rows to delete per batch (default 1000 for PostgreSQL, 200 for Redis).
|
|
629
649
|
*/
|
|
630
|
-
cleanupOldJobs: (daysToKeep?: number) => Promise<number>;
|
|
650
|
+
cleanupOldJobs: (daysToKeep?: number, batchSize?: number) => Promise<number>;
|
|
631
651
|
/**
|
|
632
652
|
* Cleanup job events that are older than the specified number of days.
|
|
653
|
+
* Deletes in batches for scale safety.
|
|
654
|
+
* @param daysToKeep - Number of days to retain events (default 30).
|
|
655
|
+
* @param batchSize - Number of rows to delete per batch (default 1000).
|
|
633
656
|
*/
|
|
634
|
-
cleanupOldJobEvents: (daysToKeep?: number) => Promise<number>;
|
|
657
|
+
cleanupOldJobEvents: (daysToKeep?: number, batchSize?: number) => Promise<number>;
|
|
635
658
|
/**
|
|
636
659
|
* Cancel a job given its ID.
|
|
637
660
|
* - This will set the job status to 'cancelled' and clear the locked_at and locked_by.
|
|
@@ -718,8 +741,6 @@ interface JobQueue<PayloadMap> {
|
|
|
718
741
|
* Tokens can be completed externally to resume a waiting job.
|
|
719
742
|
* Can be called outside of handlers (e.g., from an API route).
|
|
720
743
|
*
|
|
721
|
-
* **PostgreSQL backend only.** Throws if the backend is Redis.
|
|
722
|
-
*
|
|
723
744
|
* @param options - Optional token configuration (timeout, tags).
|
|
724
745
|
* @returns A token object with `id`.
|
|
725
746
|
*/
|
|
@@ -728,8 +749,6 @@ interface JobQueue<PayloadMap> {
|
|
|
728
749
|
* Complete a waitpoint token, resuming the associated waiting job.
|
|
729
750
|
* Can be called from anywhere (API routes, external services, etc.).
|
|
730
751
|
*
|
|
731
|
-
* **PostgreSQL backend only.** Throws if the backend is Redis.
|
|
732
|
-
*
|
|
733
752
|
* @param tokenId - The ID of the token to complete.
|
|
734
753
|
* @param data - Optional data to pass to the waiting handler.
|
|
735
754
|
*/
|
|
@@ -737,8 +756,6 @@ interface JobQueue<PayloadMap> {
|
|
|
737
756
|
/**
|
|
738
757
|
* Retrieve a waitpoint token by its ID.
|
|
739
758
|
*
|
|
740
|
-
* **PostgreSQL backend only.** Throws if the backend is Redis.
|
|
741
|
-
*
|
|
742
759
|
* @param tokenId - The ID of the token to retrieve.
|
|
743
760
|
* @returns The token record, or null if not found.
|
|
744
761
|
*/
|
|
@@ -747,8 +764,6 @@ interface JobQueue<PayloadMap> {
|
|
|
747
764
|
* Expire timed-out waitpoint tokens and resume their associated jobs.
|
|
748
765
|
* Call this periodically (e.g., alongside `reclaimStuckJobs`).
|
|
749
766
|
*
|
|
750
|
-
* **PostgreSQL backend only.** Throws if the backend is Redis.
|
|
751
|
-
*
|
|
752
767
|
* @returns The number of tokens that were expired.
|
|
753
768
|
*/
|
|
754
769
|
expireTimedOutTokens: () => Promise<number>;
|
|
@@ -906,10 +921,10 @@ interface QueueBackend {
|
|
|
906
921
|
editJob(jobId: number, updates: JobUpdates): Promise<void>;
|
|
907
922
|
/** Edit all pending jobs matching filters. Returns count. */
|
|
908
923
|
editAllPendingJobs(filters: JobFilters | undefined, updates: JobUpdates): Promise<number>;
|
|
909
|
-
/** Delete completed jobs older than N days. Returns count deleted. */
|
|
910
|
-
cleanupOldJobs(daysToKeep?: number): Promise<number>;
|
|
911
|
-
/** Delete job events older than N days. Returns count deleted. */
|
|
912
|
-
cleanupOldJobEvents(daysToKeep?: number): Promise<number>;
|
|
924
|
+
/** Delete completed jobs older than N days. Deletes in batches for scale safety. Returns count deleted. */
|
|
925
|
+
cleanupOldJobs(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
926
|
+
/** Delete job events older than N days. Deletes in batches for scale safety. Returns count deleted. */
|
|
927
|
+
cleanupOldJobEvents(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
913
928
|
/** Reclaim jobs stuck in 'processing' for too long. Returns count. */
|
|
914
929
|
reclaimStuckJobs(maxProcessingTimeMinutes?: number): Promise<number>;
|
|
915
930
|
/** Update the progress percentage (0-100) for a job. */
|
|
@@ -944,6 +959,58 @@ interface QueueBackend {
|
|
|
944
959
|
* Sets lastEnqueuedAt, lastJobId, and advances nextRunAt.
|
|
945
960
|
*/
|
|
946
961
|
updateCronScheduleAfterEnqueue(id: number, lastEnqueuedAt: Date, lastJobId: number, nextRunAt: Date | null): Promise<void>;
|
|
962
|
+
/**
|
|
963
|
+
* Transition a job from 'processing' to 'waiting' status.
|
|
964
|
+
* Persists step data so the handler can resume from where it left off.
|
|
965
|
+
*
|
|
966
|
+
* @param jobId - The job to pause.
|
|
967
|
+
* @param options - Wait configuration including optional waitUntil date, token ID, and step data.
|
|
968
|
+
*/
|
|
969
|
+
waitJob(jobId: number, options: {
|
|
970
|
+
waitUntil?: Date;
|
|
971
|
+
waitTokenId?: string;
|
|
972
|
+
stepData: Record<string, any>;
|
|
973
|
+
}): Promise<void>;
|
|
974
|
+
/**
|
|
975
|
+
* Persist step data for a job. Called after each `ctx.run()` step completes
|
|
976
|
+
* to save intermediate progress. Best-effort: should not throw.
|
|
977
|
+
*
|
|
978
|
+
* @param jobId - The job to update.
|
|
979
|
+
* @param stepData - The step data to persist.
|
|
980
|
+
*/
|
|
981
|
+
updateStepData(jobId: number, stepData: Record<string, any>): Promise<void>;
|
|
982
|
+
/**
|
|
983
|
+
* Create a waitpoint token that can pause a job until an external signal completes it.
|
|
984
|
+
*
|
|
985
|
+
* @param jobId - The job ID to associate with the token (null if created outside a handler).
|
|
986
|
+
* @param options - Optional timeout string (e.g. '10m', '1h') and tags.
|
|
987
|
+
* @returns The created waitpoint with its unique ID.
|
|
988
|
+
*/
|
|
989
|
+
createWaitpoint(jobId: number | null, options?: CreateTokenOptions): Promise<{
|
|
990
|
+
id: string;
|
|
991
|
+
}>;
|
|
992
|
+
/**
|
|
993
|
+
* Complete a waitpoint token, optionally providing output data.
|
|
994
|
+
* Moves the associated job from 'waiting' back to 'pending' so it gets picked up.
|
|
995
|
+
*
|
|
996
|
+
* @param tokenId - The waitpoint token ID to complete.
|
|
997
|
+
* @param data - Optional data to pass to the waiting handler.
|
|
998
|
+
*/
|
|
999
|
+
completeWaitpoint(tokenId: string, data?: any): Promise<void>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Retrieve a waitpoint token by its ID.
|
|
1002
|
+
*
|
|
1003
|
+
* @param tokenId - The waitpoint token ID to look up.
|
|
1004
|
+
* @returns The waitpoint record, or null if not found.
|
|
1005
|
+
*/
|
|
1006
|
+
getWaitpoint(tokenId: string): Promise<WaitpointRecord | null>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Expire timed-out waitpoint tokens and move their associated jobs back to 'pending'.
|
|
1009
|
+
* Should be called periodically (e.g., alongside reclaimStuckJobs).
|
|
1010
|
+
*
|
|
1011
|
+
* @returns The number of tokens that were expired.
|
|
1012
|
+
*/
|
|
1013
|
+
expireTimedOutWaitpoints(): Promise<number>;
|
|
947
1014
|
/** Set a pending reason for unpicked jobs of a given type. */
|
|
948
1015
|
setPendingReasonForUnpickedJobs(reason: string, jobType?: string | string[]): Promise<void>;
|
|
949
1016
|
}
|
|
@@ -971,8 +1038,26 @@ declare class PostgresBackend implements QueueBackend {
|
|
|
971
1038
|
cancelAllUpcomingJobs(filters?: JobFilters): Promise<number>;
|
|
972
1039
|
editJob(jobId: number, updates: JobUpdates): Promise<void>;
|
|
973
1040
|
editAllPendingJobs(filters: JobFilters | undefined, updates: JobUpdates): Promise<number>;
|
|
974
|
-
|
|
975
|
-
|
|
1041
|
+
/**
|
|
1042
|
+
* Delete completed jobs older than the given number of days.
|
|
1043
|
+
* Deletes in batches of 1000 to avoid long-running transactions
|
|
1044
|
+
* and excessive WAL bloat at scale.
|
|
1045
|
+
*
|
|
1046
|
+
* @param daysToKeep - Number of days to retain completed jobs (default 30).
|
|
1047
|
+
* @param batchSize - Number of rows to delete per batch (default 1000).
|
|
1048
|
+
* @returns Total number of deleted jobs.
|
|
1049
|
+
*/
|
|
1050
|
+
cleanupOldJobs(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
1051
|
+
/**
|
|
1052
|
+
* Delete job events older than the given number of days.
|
|
1053
|
+
* Deletes in batches of 1000 to avoid long-running transactions
|
|
1054
|
+
* and excessive WAL bloat at scale.
|
|
1055
|
+
*
|
|
1056
|
+
* @param daysToKeep - Number of days to retain events (default 30).
|
|
1057
|
+
* @param batchSize - Number of rows to delete per batch (default 1000).
|
|
1058
|
+
* @returns Total number of deleted events.
|
|
1059
|
+
*/
|
|
1060
|
+
cleanupOldJobEvents(daysToKeep?: number, batchSize?: number): Promise<number>;
|
|
976
1061
|
reclaimStuckJobs(maxProcessingTimeMinutes?: number): Promise<number>;
|
|
977
1062
|
/**
|
|
978
1063
|
* Batch-insert multiple job events in a single query.
|
|
@@ -1005,6 +1090,56 @@ declare class PostgresBackend implements QueueBackend {
|
|
|
1005
1090
|
* Sets lastEnqueuedAt, lastJobId, and advances nextRunAt.
|
|
1006
1091
|
*/
|
|
1007
1092
|
updateCronScheduleAfterEnqueue(id: number, lastEnqueuedAt: Date, lastJobId: number, nextRunAt: Date | null): Promise<void>;
|
|
1093
|
+
/**
|
|
1094
|
+
* Transition a job from 'processing' to 'waiting' status.
|
|
1095
|
+
* Persists step data so the handler can resume from where it left off.
|
|
1096
|
+
*
|
|
1097
|
+
* @param jobId - The job to pause.
|
|
1098
|
+
* @param options - Wait configuration including optional waitUntil date, token ID, and step data.
|
|
1099
|
+
*/
|
|
1100
|
+
waitJob(jobId: number, options: {
|
|
1101
|
+
waitUntil?: Date;
|
|
1102
|
+
waitTokenId?: string;
|
|
1103
|
+
stepData: Record<string, any>;
|
|
1104
|
+
}): Promise<void>;
|
|
1105
|
+
/**
|
|
1106
|
+
* Persist step data for a job. Called after each ctx.run() step completes.
|
|
1107
|
+
* Best-effort: does not throw to avoid killing the running handler.
|
|
1108
|
+
*
|
|
1109
|
+
* @param jobId - The job to update.
|
|
1110
|
+
* @param stepData - The step data to persist.
|
|
1111
|
+
*/
|
|
1112
|
+
updateStepData(jobId: number, stepData: Record<string, any>): Promise<void>;
|
|
1113
|
+
/**
|
|
1114
|
+
* Create a waitpoint token in the database.
|
|
1115
|
+
*
|
|
1116
|
+
* @param jobId - The job ID to associate with the token (null if created outside a handler).
|
|
1117
|
+
* @param options - Optional timeout string (e.g. '10m', '1h') and tags.
|
|
1118
|
+
* @returns The created waitpoint with its unique ID.
|
|
1119
|
+
*/
|
|
1120
|
+
createWaitpoint(jobId: number | null, options?: CreateTokenOptions): Promise<{
|
|
1121
|
+
id: string;
|
|
1122
|
+
}>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Complete a waitpoint token and move the associated job back to 'pending'.
|
|
1125
|
+
*
|
|
1126
|
+
* @param tokenId - The waitpoint token ID to complete.
|
|
1127
|
+
* @param data - Optional data to pass to the waiting handler.
|
|
1128
|
+
*/
|
|
1129
|
+
completeWaitpoint(tokenId: string, data?: any): Promise<void>;
|
|
1130
|
+
/**
|
|
1131
|
+
* Retrieve a waitpoint token by its ID.
|
|
1132
|
+
*
|
|
1133
|
+
* @param tokenId - The waitpoint token ID to look up.
|
|
1134
|
+
* @returns The waitpoint record, or null if not found.
|
|
1135
|
+
*/
|
|
1136
|
+
getWaitpoint(tokenId: string): Promise<WaitpointRecord | null>;
|
|
1137
|
+
/**
|
|
1138
|
+
* Expire timed-out waitpoint tokens and move their associated jobs back to 'pending'.
|
|
1139
|
+
*
|
|
1140
|
+
* @returns The number of tokens that were expired.
|
|
1141
|
+
*/
|
|
1142
|
+
expireTimedOutWaitpoints(): Promise<number>;
|
|
1008
1143
|
setPendingReasonForUnpickedJobs(reason: string, jobType?: string | string[]): Promise<void>;
|
|
1009
1144
|
}
|
|
1010
1145
|
|