()
| 156 | let inFlight = false |
| 157 | |
| 158 | function runTick() { |
| 159 | if (inFlight) return |
| 160 | inFlight = true |
| 161 | runAdmissionTick() |
| 162 | .then((result) => { |
| 163 | // Emit every tick so per-model queue depth and active counts form a |
| 164 | // continuous time-series that can be charted over time. |
| 165 | // metric=freebuff_waiting_room makes it filterable in the log aggregator. |
| 166 | logger.info( |
| 167 | { |
| 168 | metric: 'freebuff_waiting_room', |
| 169 | admitted: result.admitted, |
| 170 | expired: result.expired, |
| 171 | evictedBanned: result.evictedBanned, |
| 172 | queueDepthByModel: result.queueDepthByModel, |
| 173 | activeCountByModel: result.activeCountByModel, |
| 174 | skipped: result.skipped, |
| 175 | }, |
| 176 | '[FreeSessionAdmission] tick', |
| 177 | ) |
| 178 | }) |
| 179 | .catch((error) => { |
| 180 | logger.warn( |
| 181 | { error: error instanceof Error ? error.message : String(error) }, |
| 182 | '[FreeSessionAdmission] tick failed', |
| 183 | ) |
| 184 | }) |
| 185 | .finally(() => { |
| 186 | inFlight = false |
| 187 | }) |
| 188 | } |
| 189 | |
| 190 | export function startFreeSessionAdmission(): boolean { |
| 191 | if (interval) return true |
no test coverage detected