mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-14 14:06:15 +08:00
feat(queue-worker): liveness check endpoint
This commit is contained in:
parent
b5b612c35b
commit
f936befcdb
@ -81,6 +81,7 @@ import { updateGeneratedLlmsTxt } from "../lib/generate-llmstxt/generate-llmstxt
|
|||||||
import { performExtraction_F0 } from "../lib/extract/fire-0/extraction-service-f0";
|
import { performExtraction_F0 } from "../lib/extract/fire-0/extraction-service-f0";
|
||||||
import { CostTracking } from "../lib/extract/extraction-service";
|
import { CostTracking } from "../lib/extract/extraction-service";
|
||||||
import { getACUCTeam } from "../controllers/auth";
|
import { getACUCTeam } from "../controllers/auth";
|
||||||
|
import Express from "express";
|
||||||
|
|
||||||
configDotenv();
|
configDotenv();
|
||||||
|
|
||||||
@ -688,6 +689,7 @@ const processGenerateLlmsTxtJobInternal = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
let isShuttingDown = false;
|
let isShuttingDown = false;
|
||||||
|
let isWorkerStalled = false;
|
||||||
|
|
||||||
process.on("SIGINT", () => {
|
process.on("SIGINT", () => {
|
||||||
console.log("Received SIGTERM. Shutting down gracefully...");
|
console.log("Received SIGTERM. Shutting down gracefully...");
|
||||||
@ -731,7 +733,9 @@ const workerFun = async (
|
|||||||
logger.info("Can't accept connection due to RAM/CPU load");
|
logger.info("Can't accept connection due to RAM/CPU load");
|
||||||
cantAcceptConnectionCount++;
|
cantAcceptConnectionCount++;
|
||||||
|
|
||||||
if (cantAcceptConnectionCount >= 25) {
|
isWorkerStalled = cantAcceptConnectionCount >= 25;
|
||||||
|
|
||||||
|
if (isWorkerStalled) {
|
||||||
logger.error("WORKER STALLED", {
|
logger.error("WORKER STALLED", {
|
||||||
cpuUsage: await monitor.checkCpuUsage(),
|
cpuUsage: await monitor.checkCpuUsage(),
|
||||||
memoryUsage: await monitor.checkMemoryUsage(),
|
memoryUsage: await monitor.checkMemoryUsage(),
|
||||||
@ -1526,6 +1530,20 @@ async function processJob(job: Job & { id: string }, token: string) {
|
|||||||
// wsq.on("removed", j => ScrapeEvents.logJobEvent(j, "removed"));
|
// wsq.on("removed", j => ScrapeEvents.logJobEvent(j, "removed"));
|
||||||
|
|
||||||
// Start all workers
|
// Start all workers
|
||||||
|
const app = Express();
|
||||||
|
|
||||||
|
app.get("/liveness", (req, res) => {
|
||||||
|
if (isWorkerStalled) {
|
||||||
|
res.status(500).json({ ok: false });
|
||||||
|
} else {
|
||||||
|
res.status(200).json({ ok: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(3005, () => {
|
||||||
|
_logger.info("Liveness endpoint is running on port 3005");
|
||||||
|
});
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
workerFun(getScrapeQueue(), processJobInternal),
|
workerFun(getScrapeQueue(), processJobInternal),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user