1+ import type { Queue } from "../core/queue.ts" ;
2+
13export type JobStatus = 'waiting' | 'delayed' | 'reserved' | 'done' | 'failed' ;
24
35export interface JobMeta {
6+ /** Time to run - number of seconds to run the job */
47 ttr ?: number ;
8+ /** Number of seconds to delay job execution from now */
59 delay ?: number ;
10+ /** Job priority - higher numbers = higher priority (processed first) */
611 priority ?: number ;
12+ /** Job pushed at */
713 pushedAt ?: Date ;
14+ /** Job reserved at */
815 reservedAt ?: Date ;
16+ /** Job done at */
917 doneAt ?: Date ;
18+ /** SQS receipt handle */
1019 receiptHandle ?: string ; // For SQS
1120}
1221
1322/**
1423 * Job context object passed to handlers containing full job information.
1524 */
1625export interface JobContext < T > {
26+ /** Job ID */
1727 id : string ;
28+ /** Job payload */
1829 payload : T ;
30+ /** Job meta: ttr, delay, priority, pushedAt, reservedAt, doneAt, receiptHandle */
1931 meta : JobMeta ;
32+ /** Job pushed at */
2033 pushedAt ?: Date ;
34+ /** Job reserved at */
2135 reservedAt ?: Date ;
2236}
2337
2438/**
2539 * Type for a single job handler function.
2640 */
27- export type JobHandler < T > = ( job : JobContext < T > , queue : any ) => Promise < void > | void ;
41+ export type JobHandler < T , Q = Queue > = ( job : JobContext < T > , queue : Queue ) => Promise < void > | void ;
2842
2943/**
3044 * Type mapping all job types to their corresponding handlers.
@@ -36,12 +50,18 @@ export type JobHandlers<TJobMap> = {
3650
3751export interface QueueMessage {
3852 id : string ;
53+ /** Job name */
54+ name : string ;
55+ /** Job payload */
3956 payload : string ;
57+ /** Job meta: ttr, delay, priority, pushedAt, reservedAt, doneAt, receiptHandle */
4058 meta : JobMeta ;
4159}
4260
4361export interface JobData {
62+ /** Job name */
4463 name : string ;
64+ /** Job payload */
4565 payload : any ;
4666}
4767
@@ -54,59 +74,68 @@ export type QueueEvent =
5474
5575// Base options supported by all drivers (without payload)
5676export interface BaseJobOptions {
77+ /** Time to run - number of seconds to run the job */
5778 ttr ?: number ;
5879}
5980
6081// Full options interface (for internal use)
6182export interface JobOptions extends BaseJobOptions {
83+ /** Number of seconds to delay job execution from now */
6284 delay ?: number ;
85+ /** Job priority - higher numbers = higher priority (processed first) */
6386 priority ?: number ;
6487}
6588
6689// Driver-specific options interfaces (without payload)
6790export interface DbJobOptions extends BaseJobOptions {
6891 // DB adapters may or may not support delay/priority - we allow them for flexibility
6992 // The specific DatabaseAdapter implementation determines actual support
93+ /** Number of seconds to delay job execution from now. Support varies by database adapter. */
7094 delay ?: number ;
95+ /** Job priority - higher numbers = higher priority. Support varies by database adapter. */
7196 priority ?: number ;
7297}
7398
7499export interface SqsJobOptions extends BaseJobOptions {
100+ /** Number of seconds to delay job execution from now (0-900 seconds max for SQS) */
75101 delay ?: number ;
76- // SQS supports delay natively via DelaySeconds
77- // Priority is not supported (would require FIFO queues + message group IDs)
78102}
79103
80104export interface FileJobOptions extends BaseJobOptions {
105+ /** Number of seconds to delay job execution from now */
81106 delay ?: number ;
82- // File queue implements delay functionality
83- // Priority ordering is not implemented in current FileQueue
84107}
85108
86109export interface InMemoryJobOptions extends BaseJobOptions {
110+ /** Number of seconds to delay job execution from now */
87111 delay ?: number ;
112+ /** Job priority - higher numbers = higher priority (processed first) */
88113 priority ?: number ;
89- // InMemory queue supports both delay and priority
90114}
91115
92116// Combined interfaces that include payload for the new API
93117export interface BaseJobRequest < TPayload > extends BaseJobOptions {
118+ /** Job payload */
94119 payload : TPayload ;
95120}
96121
97122export interface DbJobRequest < TPayload > extends DbJobOptions {
123+ /** Job payload */
98124 payload : TPayload ;
99125}
100126
101127export interface SqsJobRequest < TPayload > extends SqsJobOptions {
128+ /** Job payload */
102129 payload : TPayload ;
103130}
104131
105132export interface FileJobRequest < TPayload > extends FileJobOptions {
133+ /** Job payload */
106134 payload : TPayload ;
107135}
108136
109137export interface InMemoryJobRequest < TPayload > extends InMemoryJobOptions {
138+ /** Job payload */
110139 payload : TPayload ;
111140}
112141
0 commit comments