Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions testplanit/workers/auditLogWorker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Prisma } from "@prisma/client";
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import {
disconnectAllTenantClients,
getPrismaClientForJob,
Expand Down Expand Up @@ -166,13 +165,8 @@ const startWorker = async () => {
});
};

// Run the worker if this file is executed directly
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as unknown as { url?: string })?.url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("[AuditLogWorker] Running as standalone process...");
startWorker().catch((err) => {
console.error("[AuditLogWorker] Failed to start:", err);
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/autoTagWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import { TagAnalysisService } from "../lib/llm/services/auto-tag/tag-analysis.service";
import type { EntityType } from "../lib/llm/services/auto-tag/types";
import { LlmManager } from "../lib/llm/services/llm-manager.service";
Expand Down Expand Up @@ -380,13 +379,8 @@ const startWorker = async () => {
});
};

// Run the worker if this file is executed directly
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("Auto-tag worker running...");
startWorker().catch((err) => {
console.error("Failed to start auto-tag worker:", err);
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/budgetAlertWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import {
disconnectAllTenantClients,
getPrismaClientForJob,
Expand Down Expand Up @@ -99,13 +98,8 @@ const startWorker = async () => {
});
};

// Run the worker if this file is executed directly
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as unknown as { url?: string })?.url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("[BudgetAlertWorker] Running as standalone process...");
startWorker().catch((err) => {
console.error("[BudgetAlertWorker] Failed to start:", err);
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/copyMoveWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import { runWithAuditContext } from "../lib/auditContext";
import type { ActorContextJobData } from "../lib/auditContextEnqueue";
import {
Expand Down Expand Up @@ -926,13 +925,8 @@ const startWorker = async () => {
});
};

// Run the worker if this file is executed directly
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("Copy-move worker running...");
startWorker().catch((err) => {
console.error("Failed to start copy-move worker:", err);
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/duplicateScanWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import { DuplicateScanService } from "../lib/services/duplicateScanService";
import {
disconnectAllTenantClients,
Expand Down Expand Up @@ -338,13 +337,8 @@ export function startDuplicateScanWorker() {
return worker;
}

// Run the worker if this file is executed directly
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("Duplicate scan worker running...");
startDuplicateScanWorker();
}
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/elasticsearchReindexWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import { getElasticsearchClient } from "~/services/elasticsearchService";
import { syncProjectIssuesToElasticsearch } from "~/services/issueSearch";
import { syncProjectMilestonesToElasticsearch } from "~/services/milestoneSearch";
Expand Down Expand Up @@ -435,13 +434,8 @@ const startWorker = async () => {
process.on("SIGTERM", shutdown);
};

// Run the worker if this file is executed directly (works with both ESM and CommonJS)
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("Elasticsearch reindex worker running...");
startWorker().catch((err) => {
console.error("Failed to start Elasticsearch reindex worker:", err);
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/emailWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import {
sendDigestEmail,
sendNotificationEmail,
Expand Down Expand Up @@ -539,13 +538,8 @@ const startWorker = async () => {
process.on("SIGTERM", shutdown);
};

// Run the worker if this file is executed directly (works with both ESM and CommonJS)
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("Email worker running...");
startWorker().catch((err) => {
console.error("Failed to start email worker:", err);
Expand Down
12 changes: 2 additions & 10 deletions testplanit/workers/forecastWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import { runWithAuditContext } from "../lib/auditContext";
import type { ActorContextJobData } from "../lib/auditContextEnqueue";
import {
Expand Down Expand Up @@ -507,15 +506,8 @@ async function startWorker() {
}
}

// Conditionally call startWorker only when this file is executed directly
// This check ensures importing the file doesn't automatically start the worker
// Works with both ESM and CommonJS
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
startWorker().catch((err) => {
console.error("Failed to start worker:", err);
process.exit(1);
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/magicSelectWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import {
createBatches,
executeBatches,
Expand Down Expand Up @@ -1137,13 +1136,8 @@ export function startMagicSelectWorker() {
return worker;
}

// Run the worker if this file is executed directly
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("Magic select worker running...");
startMagicSelectWorker();
}
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/notificationWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import {
disconnectAllTenantClients,
getPrismaClientForJob,
Expand Down Expand Up @@ -262,13 +261,8 @@ const startWorker = async () => {
process.on("SIGTERM", shutdown);
};

// Run the worker if this file is executed directly (works with both ESM and CommonJS)
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("Notification worker running...");
startWorker().catch((err) => {
console.error("Failed to start notification worker:", err);
Expand Down
8 changes: 1 addition & 7 deletions testplanit/workers/repoCacheWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import { repoFileCache } from "../lib/integrations/cache/RepoFileCache";
import {
disconnectAllTenantClients,
Expand Down Expand Up @@ -172,12 +171,7 @@ async function startWorker() {
}
}

if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
if (require.main === module) {
startWorker().catch((err) => {
console.error("Failed to start worker:", err);
process.exit(1);
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/stepSequenceScanWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import {
disconnectAllTenantClients,
getPrismaClientForJob,
Expand Down Expand Up @@ -237,13 +236,8 @@ export function startStepSequenceScanWorker() {
return worker;
}

// Run the worker if this file is executed directly
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("Step-scan worker running...");
startStepSequenceScanWorker();
}
Expand Down
10 changes: 2 additions & 8 deletions testplanit/workers/syncWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Job, Worker } from "bullmq";
import { pathToFileURL } from "node:url";
import { runWithAuditContext } from "../lib/auditContext";
import type { ActorContextJobData } from "../lib/auditContextEnqueue";
import {
Expand Down Expand Up @@ -261,13 +260,8 @@ const startWorker = async () => {
process.on("SIGTERM", shutdown);
};

// Run the worker if this file is executed directly (works with both ESM and CommonJS)
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
// Run the worker only when this file is executed directly (not on require)
if (require.main === module) {
console.log("Sync worker running...");
startWorker().catch((err) => {
console.error("Failed to start sync worker:", err);
Expand Down
8 changes: 1 addition & 7 deletions testplanit/workers/testmoImportWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import bcrypt from "bcrypt";
import { Job, Worker } from "bullmq";
import { Window as HappyDOMWindow } from "happy-dom";
import { Readable } from "node:stream";
import { pathToFileURL } from "node:url";
import { emptyEditorContent } from "../app/constants/backend";
import {
disconnectAllTenantClients,
Expand Down Expand Up @@ -7986,12 +7985,7 @@ async function startWorker() {
}

// Start worker when file is run directly (works with both ESM and CommonJS)
if (
(typeof import.meta !== "undefined" &&
import.meta.url === pathToFileURL(process.argv[1]).href) ||
typeof import.meta === "undefined" ||
(import.meta as any).url === undefined
) {
if (require.main === module) {
startWorker().catch((err) => {
console.error("Failed to start Testmo import worker:", err);
process.exit(1);
Expand Down
Loading