Skip to content

Commit a6746ec

Browse files
committed
add getQueueJobs and getJobDetails to all adapters
1 parent 0e950e2 commit a6746ec

File tree

13 files changed

+166
-24
lines changed

13 files changed

+166
-24
lines changed

.vscode/settings.json

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,30 @@
44
},
55
"editor.defaultFormatter": "esbenp.prettier-vscode",
66
"editor.formatOnSave": true,
7-
"eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
7+
"eslint.rules.customizations": [
8+
{
9+
"rule": "*",
10+
"severity": "warn"
11+
}
12+
],
813
"eslint.workingDirectories": [
9-
{ "pattern": "apps/*/" },
10-
{ "pattern": "packages/*/" },
11-
{ "pattern": "tooling/*/" }
14+
{
15+
"pattern": "apps/*/"
16+
},
17+
{
18+
"pattern": "packages/*/"
19+
},
20+
{
21+
"pattern": "tooling/*/"
22+
}
1223
],
1324
"tailwindCSS.experimental.configFile": {
14-
"apps/docs/src/app/globals.css": ["apps/docs/**"]
25+
"apps/docs/src/app/globals.css": [
26+
"apps/docs/**"
27+
],
28+
"packages/monitoring-ui/src/styles/app.css": [
29+
"packages/monitoring-ui/**"
30+
]
1531
},
1632
"tailwindCSS.emmetCompletions": true,
1733
"tailwindCSS.files.exclude": [
@@ -22,10 +38,15 @@
2238
"**/.vscode/**"
2339
],
2440
"tailwindCSS.experimental.classRegex": [
25-
["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
26-
["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
41+
[
42+
"cva\\(([^)]*)\\)",
43+
"[\"'`]([^\"'`]*).*?[\"'`]"
44+
],
45+
[
46+
"cx\\(([^)]*)\\)",
47+
"(?:'|\"|`)([^']*)(?:'|\"|`)"
48+
]
2749
],
28-
2950
"prettier.ignorePath": ".gitignore",
3051
"typescript.enablePromptUseWorkspaceTsdk": true,
3152
"typescript.preferences.autoImportFileExcludePatterns": [
@@ -48,4 +69,4 @@
4869
"files.associations": {
4970
"*.css": "tailwindcss"
5071
}
51-
}
72+
}

packages/adapter-drizzle/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"@vorsteh-queue/core": "workspace:*"
6868
},
6969
"devDependencies": {
70-
"@electric-sql/pglite": "^0.3.13",
70+
"@electric-sql/pglite": "^0.3.14",
7171
"@vorsteh-queue/eslint-config": "workspace:*",
7272
"@vorsteh-queue/prettier-config": "workspace:*",
7373
"@vorsteh-queue/shared-tests": "workspace:*",
@@ -77,10 +77,10 @@
7777
"eslint": "^9.39.1",
7878
"postgres": "^3.4.7",
7979
"prettier": "^3.6.2",
80-
"rolldown": "1.0.0-beta.47",
80+
"rolldown": "1.0.0-beta.49",
8181
"rollup-plugin-delete": "^3.0.1",
82-
"typescript": "^5.9.3",
83-
"vitest": "^4.0.7"
82+
"typescript": "5.9.3",
83+
"vitest": "^4.0.8"
8484
},
8585
"peerDependencies": {
8686
"drizzle-orm": ">=0.44.3"

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,28 @@ export class PostgresQueueAdapter<
198198
return result
199199
}
200200

201+
async getQueueJobs(): Promise<BaseJob[]> {
202+
const jobs = await this.db
203+
.select()
204+
.from(this.model)
205+
.where(eq(this.model.queueName, this.queueName))
206+
207+
return jobs.map((job) => this.transformJob(job as schema.QueueJob))
208+
}
209+
210+
async getJobDetails(id: string): Promise<BaseJob> {
211+
const [job] = await this.db
212+
.select()
213+
.from(this.model)
214+
.where(and(eq(this.model.queueName, this.queueName), eq(this.model.id, id)))
215+
216+
if (!job) {
217+
throw new Error(`Job with ID ${id} not found in queue ${this.queueName}`)
218+
}
219+
220+
return this.transformJob(job as schema.QueueJob)
221+
}
222+
201223
async clearJobs(status?: JobStatus): Promise<number> {
202224
const conditions = [eq(this.model.queueName, this.queueName)]
203225
if (status) {

packages/adapter-kysely/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"@vorsteh-queue/core": "workspace:*"
7272
},
7373
"devDependencies": {
74-
"@electric-sql/pglite": "^0.3.13",
74+
"@electric-sql/pglite": "^0.3.14",
7575
"@vorsteh-queue/eslint-config": "workspace:*",
7676
"@vorsteh-queue/prettier-config": "workspace:*",
7777
"@vorsteh-queue/shared-tests": "workspace:*",
@@ -82,10 +82,10 @@
8282
"kysely-postgres-js": "^3.0.0",
8383
"postgres": "^3.4.7",
8484
"prettier": "^3.6.2",
85-
"rolldown": "1.0.0-beta.47",
85+
"rolldown": "1.0.0-beta.49",
8686
"rollup-plugin-delete": "^3.0.1",
87-
"typescript": "^5.9.3",
88-
"vitest": "^4.0.7"
87+
"typescript": "5.9.3",
88+
"vitest": "^4.0.8"
8989
},
9090
"peerDependencies": {
9191
"kysely": ">=0.28.0"

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,30 @@ export class PostgresQueueAdapter extends BaseQueueAdapter {
225225
return result
226226
}
227227

228+
async getQueueJobs(): Promise<BaseJob[]> {
229+
const jobs = await this.customDbClient
230+
.selectFrom(`${this.schemaName}.${this.tableName}` as unknown as "tablename")
231+
.selectAll()
232+
.where("queue_name", "=", this.queueName)
233+
.execute()
234+
235+
return jobs.map((job) => this.transformJob(job))
236+
}
237+
238+
async getJobDetails(id: string): Promise<BaseJob> {
239+
const job = await this.customDbClient
240+
.selectFrom(`${this.schemaName}.${this.tableName}` as unknown as "tablename")
241+
.selectAll()
242+
.where("queue_name", "=", this.queueName)
243+
.where("id", "=", id)
244+
.executeTakeFirst()
245+
246+
if (!job) {
247+
throw new Error(`Job with ID ${id} not found in queue ${this.queueName}`)
248+
}
249+
return this.transformJob(job)
250+
}
251+
228252
async clearJobs(status?: JobStatus): Promise<number> {
229253
const query = this.customDbClient
230254
.deleteFrom(`${this.schemaName}.${this.tableName}` as unknown as "tablename")

packages/adapter-prisma/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@
6969
"eslint": "^9.39.1",
7070
"prettier": "^3.6.2",
7171
"prisma": "^6.19.0",
72-
"rolldown": "1.0.0-beta.47",
72+
"rolldown": "1.0.0-beta.49",
7373
"rollup-plugin-delete": "^3.0.1",
7474
"testcontainers": "^11.8.0",
75-
"typescript": "^5.9.3",
76-
"vitest": "^4.0.7"
75+
"typescript": "5.9.3",
76+
"vitest": "^4.0.8"
7777
},
7878
"peerDependencies": {
7979
"@prisma/client": ">=6.1.0"

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,29 @@ export class PostgresPrismaQueueAdapter extends BaseQueueAdapter {
167167
return result
168168
}
169169

170+
async getQueueJobs(): Promise<BaseJob[]> {
171+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
172+
const jobs = (await this.db[this.modelName]!.findMany({
173+
where: { queueName: this.queueName },
174+
orderBy: { createdAt: "desc" },
175+
})) as QueueJob[]
176+
177+
return jobs.map((job) => this.transformJob(job))
178+
}
179+
180+
async getJobDetails(id: string): Promise<BaseJob> {
181+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
182+
const job = (await this.db[this.modelName]!.findFirst({
183+
where: { id },
184+
})) as QueueJob | null
185+
186+
if (!job) {
187+
throw new Error(`Job with ID ${id} not found in queue ${this.queueName}`)
188+
}
189+
190+
return this.transformJob(job)
191+
}
192+
170193
async clearJobs(status?: JobStatus): Promise<number> {
171194
const where: Record<string, unknown> = { queueName: this.queueName }
172195
if (status) where.status = status

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@
7272
"@vorsteh-queue/prettier-config": "workspace:*",
7373
"@vorsteh-queue/tsconfig": "workspace:*",
7474
"eslint": "^9.39.1",
75-
"rolldown": "1.0.0-beta.47",
75+
"rolldown": "1.0.0-beta.49",
7676
"rollup-plugin-delete": "^3.0.1",
77-
"typescript": "^5.9.3",
78-
"vitest": "^4.0.7"
77+
"typescript": "5.9.3",
78+
"vitest": "^4.0.8"
7979
},
8080
"publishConfig": {
8181
"exports": {

packages/core/src/adapters/base.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ export abstract class BaseQueueAdapter implements QueueAdapter {
7979
*/
8080
abstract getQueueStats(): Promise<QueueStats>
8181

82+
/**
83+
* Get all jobs in the queue
84+
*
85+
* @returns Promise resolving to an array of all jobs in the queue
86+
*/
87+
abstract getQueueJobs(): Promise<BaseJob[]>
88+
89+
/**
90+
* Get detailed information about a specific job by ID
91+
*
92+
* @param id Job ID to retrieve
93+
* @returns Promise resolving to the job details
94+
*/
95+
abstract getJobDetails(id: string): Promise<BaseJob>
96+
8297
/**
8398
* Clear jobs from the queue
8499
*

packages/core/src/adapters/memory.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ export class MemoryQueueAdapter extends BaseQueueAdapter {
120120
return Promise.resolve(stats)
121121
}
122122

123+
getQueueJobs(): Promise<BaseJob[]> {
124+
return Promise.resolve(Array.from(this.jobs.values()))
125+
}
126+
127+
getJobDetails(id: string): Promise<BaseJob> {
128+
{
129+
const job = this.jobs.get(id)
130+
if (!job) {
131+
return Promise.reject(new Error(`Job with ID ${id} not found`))
132+
}
133+
return Promise.resolve(job)
134+
}
135+
}
136+
123137
clearJobs(status?: JobStatus): Promise<number> {
124138
if (!status) {
125139
const count = this.jobs.size

0 commit comments

Comments
 (0)