Skip to content

Commit

Permalink
fix(type): correct process argument
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
RomainLanz committed May 17, 2024
1 parent fd52593 commit d27e830
Showing 1 changed file with 54 additions and 47 deletions.
101 changes: 54 additions & 47 deletions adonis-typings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,58 @@
*/

declare module '@ioc:Rlanz/Queue' {
import type { ConnectionOptions, WorkerOptions, QueueOptions, JobsOptions, Job, Queue as BullQueue } from 'bullmq';

export type DataForJob<K extends string> = K extends keyof JobsList
? JobsList[K]
: Record<string, unknown>;

export type DispatchOptions = JobsOptions & {
queueName?: 'default' | string;
};

export type QueueConfig = {
connection: ConnectionOptions;
queue: Omit<QueueOptions, 'connection'>;
worker: Omit<WorkerOptions, 'connection'>;
jobs: JobsOptions;
};

interface QueueContract {
dispatch<K extends keyof JobsList>(
job: K,
payload: DataForJob<K>,
options?: DispatchOptions
): Promise<Job>;
dispatch<K extends string>(
job: K,
payload: DataForJob<K>,
options?: DispatchOptions
): Promise<Job>;
process(): Promise<void>;
clear(queue: string): Promise<void>;
list(): Map<string, BullQueue>;
get(queueName: string): BullQueue | undefined;
}

export interface JobHandlerContract {
handle(payload: any): Promise<void>;
failed(): Promise<void>;
}

/**
* An interface to define typed queues/jobs
*/
export interface JobsList {}

export const Queue: QueueContract;

export { Job };
import type {
ConnectionOptions,
WorkerOptions,
QueueOptions,
JobsOptions,
Job,
Queue as BullQueue,
} from 'bullmq'

export type DataForJob<K extends string> = K extends keyof JobsList
? JobsList[K]
: Record<string, unknown>

export type DispatchOptions = JobsOptions & {
queueName?: 'default' | string
}

export type QueueConfig = {
connection: ConnectionOptions
queue: Omit<QueueOptions, 'connection'>
worker: Omit<WorkerOptions, 'connection'>
jobs: JobsOptions
}

interface QueueContract {
dispatch<K extends keyof JobsList>(
job: K,
payload: DataForJob<K>,
options?: DispatchOptions
): Promise<Job>
dispatch<K extends string>(
job: K,
payload: DataForJob<K>,
options?: DispatchOptions
): Promise<Job>
process(queue: string): Promise<void>
clear(queue: string): Promise<void>
list(): Map<string, BullQueue>
get(queueName: string): BullQueue | undefined
}

export interface JobHandlerContract {
handle(payload: any): Promise<void>
failed(): Promise<void>
}

/**
* An interface to define typed queues/jobs
*/
export interface JobsList {}

export const Queue: QueueContract

export { Job }
}

0 comments on commit d27e830

Please sign in to comment.