Skip to content

Commit

Permalink
change worker and instrumentation ID to include hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
radityaharya committed Jan 20, 2024
1 parent 818f9fc commit 0c4585c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -18,6 +19,7 @@ export const register = async () => {
maxRetriesPerRequest: null,
});


new Worker(
"workflowQueue",
async (job) => {
Expand Down
3 changes: 2 additions & 1 deletion worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down

0 comments on commit 0c4585c

Please sign in to comment.