Skip to content

Commit

Permalink
Add bullmq killer
Browse files Browse the repository at this point in the history
  • Loading branch information
pastelsky committed Jan 2, 2024
1 parent 90d7de0 commit 953474b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions server/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,30 @@ import path from "path";
import logger from "../common/logger";
import { config } from "dotenv";
import { InstallPackageOptions } from "./package/types";
import { execSync } from "node:child_process";

config({
path: path.join(__dirname, "../.env"),
});

/**
* When pm2 restarts the server, its possible for worker processes to be left behind.
* Here we force kill all such processes
*/
function killAllBullMQProcesses(processName: string) {
if (process.env.NODE_ENV !== "production") return;

const command = `ps aux | grep '${processName}' | grep -v grep | awk '{print $2}' | xargs -r kill -9`;
try {
execSync(command);
console.log(`Killed processes with name containing '${processName}'`);
} catch (error) {
console.error(`Error killing processes: ${error}`);
}
}

killAllBullMQProcesses("bullmq");

const redisOptions = {
port: 6379,
host: "localhost",
Expand Down

0 comments on commit 953474b

Please sign in to comment.