Skip to content

Commit

Permalink
fix: radar infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcrt committed Feb 19, 2024
1 parent 9eb9e52 commit 616c589
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/backend/src/jobs/radar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import sql from "@/src/utils/db"
import { convertChecksToSQL } from "@/src/utils/filters"
import { FilterLogic } from "shared"
import { runChecksOnRun } from "../checks/runChecks"
import { sleep } from "../utils/misc"

const RUNS_BATCH_SIZE = 300 // small batch size to cycle through radars faster making it more equitable
const PARALLEL_BATCH_SIZE = 5
Expand Down Expand Up @@ -44,6 +45,13 @@ async function getRadarRuns(radar: any) {
let jobRunning = false

async function radarJob() {
const [{ count: runsCount }] = await sql`select count(*)::int from run`

if (runsCount === 0) {
console.log("[Radars] No runs, waiting 20 seconds")
await sleep(20000)
}

if (jobRunning) {
return console.warn("JOB: radar scan already running. skipping")
}
Expand Down Expand Up @@ -89,15 +97,9 @@ async function radarJob() {
}

export default async function runRadarJob() {
// run in a while loop
while (true) {
try {
console.time("JOB: radar scan")
const didSomeWork = await radarJob()

// if (didSomeWork) {
console.timeEnd("JOB: radar scan")
// }
await radarJob()
} catch (error) {
console.error(error)
}
Expand Down

0 comments on commit 616c589

Please sign in to comment.