Merge pull request #398 from mendableai/nsc/slack-alerts-1

CI for alerts instead
This commit is contained in:
Nicolas 2024-07-12 19:52:34 -04:00 committed by GitHub
commit da3e6525a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 4 deletions

20
.github/workflows/check-queues.yml vendored Normal file
View File

@ -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"

View File

@ -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) => {

View File

@ -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);