11import type { Kysely } from "kysely"
22import { sql } from "kysely"
33
4- import type { BaseJob , JobStatus , QueueStats , SerializedError } from "@vorsteh-queue/core"
4+ import type { BaseJob , BatchJob , JobStatus , QueueStats , SerializedError } from "@vorsteh-queue/core"
55import { asUtc , BaseQueueAdapter , serializeError } from "@vorsteh-queue/core"
66
77import type { DB , InsertQueueJobValue , QueueJob } from "./types"
@@ -104,8 +104,8 @@ export class PostgresQueueAdapter extends BaseQueueAdapter {
104104 }
105105
106106 async addJobs < TJobPayload , TJobResult = unknown > (
107- jobs : readonly Omit < BaseJob < TJobPayload , TJobResult > , "id" | "createdAt" > [ ] ,
108- ) : Promise < readonly BaseJob < TJobPayload , TJobResult > [ ] > {
107+ jobs : Omit < BatchJob < TJobPayload , TJobResult > , "id" | "createdAt" > [ ] ,
108+ ) : Promise < BatchJob < TJobPayload , TJobResult > [ ] > {
109109 if ( ! jobs . length ) return [ ]
110110
111111 const values : InsertQueueJobValue [ ] = jobs . map ( ( job ) => ( {
@@ -116,11 +116,11 @@ export class PostgresQueueAdapter extends BaseQueueAdapter {
116116 priority : job . priority ,
117117 attempts : job . attempts ,
118118 max_attempts : job . maxAttempts ,
119- process_at : sql `${ job . processAt . toISOString ( ) } ::timestamptz` ,
120- cron : job . cron ,
121- repeat_every : job . repeatEvery ,
122- repeat_limit : job . repeatLimit ,
123- repeat_count : job . repeatCount ,
119+ process_at : sql `${ asUtc ( new Date ( ) ) . toISOString ( ) } ::timestamptz` ,
120+ cron : null ,
121+ repeat_every : null ,
122+ repeat_limit : null ,
123+ repeat_count : 0 ,
124124 timeout : job . timeout ,
125125 } ) )
126126
@@ -134,7 +134,7 @@ export class PostgresQueueAdapter extends BaseQueueAdapter {
134134 throw new Error ( "Failed to create jobs" )
135135 }
136136
137- return results . map ( ( row ) => this . transformJob ( row ) as BaseJob < TJobPayload , TJobResult > )
137+ return results . map ( ( row ) => this . transformJob ( row ) as BatchJob < TJobPayload , TJobResult > )
138138 }
139139
140140 async updateJobStatus (
@@ -272,9 +272,10 @@ export class PostgresQueueAdapter extends BaseQueueAdapter {
272272 // BatchJob omits scheduling fields, so we strip them
273273 return jobs . map ( ( job ) => {
274274 // eslint-disable-next-line @typescript-eslint/no-unused-vars
275- const { cron, repeat_every, repeat_limit, repeat_count, process_at, ...rest } = job
275+ const { cron, repeat_every, repeat_limit, repeat_count, process_at, status , ...rest } = job
276276 return {
277277 ...rest ,
278+ status : status as JobStatus ,
278279 maxAttempts : job . max_attempts ,
279280 createdAt : job . created_at ,
280281 processAt : job . process_at ,
@@ -284,7 +285,7 @@ export class PostgresQueueAdapter extends BaseQueueAdapter {
284285 error : job . error as SerializedError | undefined ,
285286 result : job . result ,
286287 progress : job . progress ?? 0 ,
287- // Remove scheduling fields for BatchJob
288+ timeout : job . timeout ?? undefined ,
288289 }
289290 } )
290291 }
0 commit comments