@@ -9,29 +9,95 @@ export abstract class BaseQueueAdapter implements QueueAdapter {
99
1010 /**
1111 * Set the queue name. Called by the Queue class during initialization.
12+ *
1213 * @internal
1314 */
1415 setQueueName ( queueName : string ) : void {
1516 this . queueName = queueName
1617 }
1718
19+ /** Connect to the database/storage backend */
1820 abstract connect ( ) : Promise < void >
21+
22+ /** Disconnect from the database/storage backend */
1923 abstract disconnect ( ) : Promise < void >
24+
25+ /**
26+ * Add a new job to the queue storage
27+ *
28+ * @param job - Job data without id and createdAt
29+ * @returns Promise resolving to the created job with id and createdAt
30+ */
2031 abstract addJob < TJobPayload , TJobResult = unknown > (
2132 job : Omit < BaseJob < TJobPayload , TJobResult > , "id" | "createdAt" > ,
2233 ) : Promise < BaseJob < TJobPayload , TJobResult > >
34+
35+ /**
36+ * Update job status and optionally set error or result
37+ *
38+ * @param id - Job ID to update
39+ * @param status - New job status
40+ * @param error - Optional error data for failed jobs
41+ * @param result - Optional result data for completed jobs
42+ */
2343 abstract updateJobStatus (
2444 id : string ,
2545 status : JobStatus ,
2646 error ?: unknown ,
2747 result ?: unknown ,
2848 ) : Promise < void >
49+
50+ /**
51+ * Update job progress percentage
52+ *
53+ * @param id - Job ID to update
54+ * @param progress - Progress percentage (0-100)
55+ */
2956 abstract updateJobProgress ( id : string , progress : number ) : Promise < void >
57+
58+ /**
59+ * Increment job attempt counter
60+ *
61+ * @param id - Job ID to update
62+ */
3063 abstract incrementJobAttempts ( id : string ) : Promise < void >
64+
65+ /**
66+ * Get queue statistics by job status
67+ *
68+ * @returns Promise resolving to queue statistics
69+ */
3170 abstract getQueueStats ( ) : Promise < QueueStats >
71+
72+ /**
73+ * Clear jobs from the queue
74+ *
75+ * @param status - Optional status filter, clears all jobs if not provided
76+ * @returns Promise resolving to number of jobs cleared
77+ */
3278 abstract clearJobs ( status ?: JobStatus ) : Promise < number >
79+
80+ /**
81+ * Clean up old jobs, keeping only the most recent N jobs
82+ *
83+ * @param status - Job status to clean up
84+ * @param keepCount - Number of jobs to keep
85+ * @returns Promise resolving to number of jobs cleaned up
86+ */
3387 abstract cleanupJobs ( status : JobStatus , keepCount : number ) : Promise < number >
88+
89+ /**
90+ * Get the number of pending jobs in the queue
91+ * @returns Promise resolving to number of pending jobs
92+ */
3493 abstract size ( ) : Promise < number >
94+
95+ /**
96+ * Execute a function within a database transaction
97+ *
98+ * @param fn - Function to execute in transaction
99+ * @returns Promise resolving to the function's return value
100+ */
35101 abstract transaction < TResult > ( fn : ( ) => Promise < TResult > ) : Promise < TResult >
36102
37103 /**
@@ -54,9 +120,29 @@ export abstract class BaseQueueAdapter implements QueueAdapter {
54120 return this . getPendingJobByPriority ( )
55121 }
56122
123+ /**
124+ * Get a delayed job that is ready to be processed
125+ *
126+ * @param now - Current timestamp to compare against processAt
127+ * @returns Promise resolving to ready delayed job or null
128+ * @protected
129+ */
57130 protected abstract getDelayedJobReady ( now : Date ) : Promise < BaseJob | null >
131+
132+ /**
133+ * Get the next pending job ordered by priority and creation time
134+ *
135+ * @returns Promise resolving to next pending job or null
136+ * @protected
137+ */
58138 protected abstract getPendingJobByPriority ( ) : Promise < BaseJob | null >
59139
140+ /**
141+ * Generate a unique job ID
142+ *
143+ * @returns Unique string identifier
144+ * @protected
145+ */
60146 protected generateId ( ) : string {
61147 return `${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . substring ( 2 , 9 ) } `
62148 }
0 commit comments