From 952363fca38f1a62c65542bdbb8a99df779f24c0 Mon Sep 17 00:00:00 2001 From: Jakob Date: Thu, 4 Jul 2024 17:11:34 -0700 Subject: [PATCH] refactor: Add deletePackData type and update embedderWorkerPlugin to handle deletePack job --- .../embedder/worker/src/lib/embedder-worker.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/embedder/worker/src/lib/embedder-worker.ts b/packages/embedder/worker/src/lib/embedder-worker.ts index 27b1cc87bb..f7bc7523e3 100644 --- a/packages/embedder/worker/src/lib/embedder-worker.ts +++ b/packages/embedder/worker/src/lib/embedder-worker.ts @@ -2,6 +2,7 @@ import { err, info } from '@magickml/embedder-config' import { processEmbedJob, processDeleteLoaderJob, + processDeletePackJob, } from '@magickml/embedder-queue' import { Worker } from 'bullmq' import { defineNitroPlugin } from 'nitropack/runtime' @@ -22,11 +23,12 @@ export const embedderWorkerPlugin = defineNitroPlugin(() => { type ProcessJobData = { jobId: string } type DeleteLoaderData = { loaderId: string; path: string } + type DeletePackData = { packId: string } const worker = new Worker< - ProcessJobData | DeleteLoaderData, + ProcessJobData | DeleteLoaderData | DeletePackData, void, - 'processJob' | 'deleteLoader' + 'processJob' | 'deleteLoader' | 'deletePack' >( queueName, async job => { @@ -46,6 +48,14 @@ export const embedderWorkerPlugin = defineNitroPlugin(() => { } catch (error) { err(`Error deleting loader ${loaderId}`, error) } + } else if (job.name === 'deletePack') { + const { packId } = job.data as DeletePackData + console.log(`Deleting pack ${packId}`) + try { + await processDeletePackJob(packId) + } catch (error) { + err(`Error deleting pack ${packId}`, error) + } } }, { connection }