From 0c4585c26d577d8a897b1731e11020d57491e9be Mon Sep 17 00:00:00 2001 From: Raditya Harya Date: Sat, 20 Jan 2024 12:16:10 +0000 Subject: [PATCH] change worker and instrumentation ID to include hostname --- src/instrumentation.ts | 4 +++- worker/worker.ts | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/instrumentation.ts b/src/instrumentation.ts index 30e9c8b..17e0932 100644 --- a/src/instrumentation.ts +++ b/src/instrumentation.ts @@ -4,11 +4,12 @@ import { type Workflow } from "~/lib/workflow/types"; import { getAccessTokenFromUserId } from "~/server/db/helper"; import { v4 as uuid } from "uuid"; -const WORKER_ID = process.env.WORKER_ID ?? `instrumentation-${uuid()}`; export const register = async () => { //This if statement is important, read here: https://nextjs.org/docs/app/building-your-application/optimizing/instrumentation if (process.env.NEXT_RUNTIME === "nodejs" && !process.env.NO_WORKER) { + const hostname = (await import("os")).hostname(); + const WORKER_ID = hostname + "-" + `${process.env.WORKER_ID ?? 'instrumentation-' + uuid()}` console.log("Registering worker"); console.log("Worker ID", WORKER_ID); const { Worker } = await import("bullmq"); @@ -18,6 +19,7 @@ export const register = async () => { maxRetriesPerRequest: null, }); + new Worker( "workflowQueue", async (job) => { diff --git a/worker/worker.ts b/worker/worker.ts index 05ee958..0ff27d6 100644 --- a/worker/worker.ts +++ b/worker/worker.ts @@ -6,9 +6,10 @@ import { Worker } from "bullmq"; import { updateWorkflowJob } from "../src/app/api/workflow/workflowQueue"; import Redis from "ioredis"; import { v4 as uuidv4 } from "uuid"; +import os from "os"; const CONCURRENCY = 5; -const WORKER_ID = process.env.WORKER_ID ?? "worker-" + uuidv4(); +const WORKER_ID = os.hostname() + "-" + `${process.env.WORKER_ID ?? 'worker-' + uuidv4()}` console.log(`