Skip to content

Commit cc7e451

Browse files
committed
add missing JSDocs
1 parent ccaacc2 commit cc7e451

File tree

6 files changed

+253
-2
lines changed

6 files changed

+253
-2
lines changed

packages/adapter-drizzle/src/postgres-adapter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type DrizzleDatabase =
1616
/**
1717
* PostgreSQL adapter for the queue system using Drizzle ORM.
1818
* Supports PostgreSQL databases through Drizzle ORM with node-postgres, postgres.js, or PGlite.
19+
* Provides persistent job storage with ACID transactions and optimized job selection.
1920
*
2021
* @example
2122
* ```typescript
@@ -25,6 +26,7 @@ type DrizzleDatabase =
2526
* const pool = new Pool({ connectionString: "postgresql://..." })
2627
* const db = drizzle(pool)
2728
* const adapter = new PostgresQueueAdapter(db)
29+
* const queue = new Queue(adapter, { name: "my-queue" })
2830
* ```
2931
*/
3032
export class PostgresQueueAdapter extends BaseQueueAdapter {

packages/adapter-prisma/src/postgres-adapter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import type { QueueJobModel as QueueJob } from "./generated/prisma/models"
77
/**
88
* PostgreSQL adapter for the queue system using Prisma ORM.
99
* Uses raw SQL with SKIP LOCKED for critical job selection methods to prevent race conditions.
10+
* Provides persistent job storage with type-safe database operations and automatic migrations.
1011
*
1112
* @example
1213
* ```typescript
1314
* import { PrismaClient } from '@prisma/client'
1415
* import { PostgresPrismaQueueAdapter } from '@vorsteh-queue/adapter-prisma'
1516
*
1617
* const prisma = new PrismaClient()
17-
* const queue = new Queue(new PostgresPrismaQueueAdapter(prisma), { name: "my-queue" })
18+
* const adapter = new PostgresPrismaQueueAdapter(prisma)
19+
* const queue = new Queue(adapter, { name: "my-queue" })
1820
* ```
1921
*/
2022
export class PostgresPrismaQueueAdapter extends BaseQueueAdapter {

packages/core/src/adapters/base.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

packages/core/src/adapters/memory.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ import type { BaseJob, JobStatus, QueueStats } from "../../types"
22
import { serializeError } from "../utils/error"
33
import { BaseQueueAdapter } from "./base"
44

5+
/**
6+
* In-memory queue adapter for testing and development.
7+
* Stores all job data in memory - data is lost when the process exits.
8+
*
9+
* @example
10+
* ```typescript
11+
* const adapter = new MemoryQueueAdapter()
12+
* const queue = new Queue(adapter, { name: "test-queue" })
13+
* ```
14+
*/
515
export class MemoryQueueAdapter extends BaseQueueAdapter {
616
private jobs = new Map<string, BaseJob>()
717
private connected = false

packages/core/src/core/job-wrapper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export function createJobWrapper<TJobPayload>(
77
): JobWithProgress<TJobPayload> {
88
return {
99
...job,
10+
/**
11+
* Updates the progress value of the job in the queue
12+
* @param value - The progress value to set (between 0 and 100)
13+
* @returns Promise that resolves when the progress is updated
14+
*/
1015
updateProgress: async (value: number): Promise<void> => {
1116
await queue.updateJobProgress(job.id, value)
1217
},

0 commit comments

Comments
 (0)