diff --git a/.github/workflows/check-queues.yml b/.github/workflows/check-queues.yml new file mode 100644 index 00000000..5cb5d9ca --- /dev/null +++ b/.github/workflows/check-queues.yml @@ -0,0 +1,20 @@ +name: Check Queues +on: + schedule: + - cron: '*/5 * * * *' + +env: + BULL_AUTH_KEY: ${{ secrets.BULL_AUTH_KEY }} + +jobs: + clean-jobs: + runs-on: ubuntu-latest + steps: + - name: Send GET request to check queues + run: | + response=$(curl --write-out '%{http_code}' --silent --output /dev/null --max-time 180 https://api.firecrawl.dev/admin/${{ secrets.BULL_AUTH_KEY }}/check-queues) + if [ "$response" -ne 200 ]; then + echo "Failed to check queues. Response: $response" + exit 1 + fi + echo "Successfully checked queues. Response: $response" diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index 0ef67e6f..198288f6 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -10,7 +10,7 @@ import cluster from "cluster"; import os from "os"; import { Job } from "bull"; import { sendSlackWebhook } from "./services/alerts/slack"; -import { initAlerts } from "./services/alerts"; +import { checkAlerts } from "./services/alerts"; const { createBullBoard } = require("@bull-board/api"); const { BullAdapter } = require("@bull-board/api/bullAdapter"); @@ -35,10 +35,10 @@ if (cluster.isMaster) { } }); - initAlerts(); } else { const app = express(); + global.isProduction = process.env.IS_PRODUCTION === "true"; app.use(bodyParser.urlencoded({ extended: true })); @@ -246,6 +246,19 @@ if (cluster.isMaster) { } }); + app.get( + `/admin/${process.env.BULL_AUTH_KEY}/check-queues`, + async (req, res) => { + try { + await checkAlerts(); + return res.status(200).send("Alerts initialized"); + } catch (error) { + console.error("Failed to initialize alerts:", error); + return res.status(500).send("Failed to initialize alerts"); + } + } + ); + app.get( `/admin/${process.env.BULL_AUTH_KEY}/clean-before-24h-complete-jobs`, async (req, res) => { diff --git a/apps/api/src/services/alerts/index.ts b/apps/api/src/services/alerts/index.ts index 8d16489d..b388b1ee 100644 --- a/apps/api/src/services/alerts/index.ts +++ b/apps/api/src/services/alerts/index.ts @@ -1,7 +1,7 @@ import { getWebScraperQueue } from "../queue-service"; import { sendSlackWebhook } from "./slack"; -export function initAlerts() { +export async function checkAlerts() { try { if ( process.env.SLACK_WEBHOOK_URL && @@ -51,7 +51,8 @@ export function initAlerts() { await checkWaitingQueue(); }; - setInterval(checkAll, 5 * 60 * 1000); // Run every 5 minutes + await checkAll(); + // setInterval(checkAll, 10000); // Run every } } catch (error) { console.error("Failed to initialize alerts:", error);