Batch enqueue types

This commit is contained in:
nicktrn
2023-11-27 20:53:00 +00:00
parent 5e37d955a4
commit f648fb6e10
4 changed files with 10 additions and 6 deletions
+7 -3
View File
@@ -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;
+1 -1
View File
@@ -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))