Batch enqueue types
This commit is contained in:
@@ -82,11 +82,15 @@ type BatchTaskSpec = TaskSpec & {
|
||||
maxPayloads?: number;
|
||||
};
|
||||
|
||||
export type ZodWorkerEnqueueOptions = TaskSpec &
|
||||
export type ZodWorkerBatchEnqueueOptions = TaskSpec &
|
||||
Pick<BatchTaskSpec, "maxPayloads"> & {
|
||||
tx?: PrismaClientOrTransaction;
|
||||
};
|
||||
|
||||
export type ZodWorkerEnqueueOptions = TaskSpec & {
|
||||
tx?: PrismaClientOrTransaction;
|
||||
};
|
||||
|
||||
export type ZodWorkerDequeueOptions = {
|
||||
tx?: PrismaClientOrTransaction;
|
||||
};
|
||||
@@ -313,13 +317,13 @@ export class ZodWorker<TMessageCatalog extends MessageCatalogSchema> {
|
||||
return job;
|
||||
}
|
||||
|
||||
public async enqueueBatch<
|
||||
public async batchEnqueue<
|
||||
K extends keyof TMessageCatalog,
|
||||
TPayload extends z.infer<TMessageCatalog[K]>
|
||||
>(
|
||||
identifier: K,
|
||||
payload: TPayload extends any[] ? TPayload : never,
|
||||
options?: ZodWorkerEnqueueOptions
|
||||
options?: ZodWorkerBatchEnqueueOptions
|
||||
): Promise<GraphileJob> {
|
||||
const task = this.#tasks[identifier];
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function action({ request }: ActionArgs) {
|
||||
|
||||
const body: any = await request.json();
|
||||
|
||||
await workerQueue.enqueueBatch(
|
||||
await workerQueue.batchEnqueue(
|
||||
"simulateBatch",
|
||||
[
|
||||
{
|
||||
|
||||
@@ -69,7 +69,7 @@ export class GraphileMigrationHelperService {
|
||||
flags := flags,
|
||||
job_key_mode := job_key_mode
|
||||
);
|
||||
|
||||
|
||||
IF max_payloads IS NOT NULL
|
||||
AND json_array_length(v_job.payload) >= max_payloads THEN
|
||||
UPDATE ${env.WORKER_SCHEMA}.jobs SET run_at = NOW() WHERE jobs.id = v_job.id RETURNING * INTO v_job;
|
||||
|
||||
@@ -167,7 +167,7 @@ if (env.NODE_ENV === "production") {
|
||||
export async function init() {
|
||||
const migrationHelper = new GraphileMigrationHelperService();
|
||||
await migrationHelper.call();
|
||||
|
||||
|
||||
// const pgNotify = new PgNotifyService();
|
||||
// await pgNotify.call("trigger:graphile:migrate", { latestMigration: 10 });
|
||||
// await new Promise((resolve) => setTimeout(resolve, 10000))
|
||||
|
||||
Reference in New Issue
Block a user