Skip to content

Commit

Permalink
feat: restart after too many errors (#41)
Browse files Browse the repository at this point in the history
* feat: restart after too many errors

* ci: fix the build
  • Loading branch information
philipparndt authored Oct 2, 2024
1 parent a420886 commit 5ba74ed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
npm run build
- name: Build container
run: docker-compose build
run: docker compose build
18 changes: 17 additions & 1 deletion app/lib/polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { ShadingActor } from "./eltako/api/eltako-api"
import { log } from "./logger"
import { publish } from "./mqtt/mqtt-client"

let pollingErrorCount = 0
let successCount = 0

export const registerPolling = (actors: ShadingActor[], pollingIntervalMs: number) => {
const intervals: any[] = []
for (const actor of actors) {
Expand All @@ -12,9 +15,22 @@ export const registerPolling = (actors: ShadingActor[], pollingIntervalMs: numbe
const displayName = actor.getDisplayName()
log.debug("Polling result", { position, displayName })
publish({ position }, displayName)
successCount++

if (pollingErrorCount > 0 && successCount > (5 * actors.length)) {
log.info("Good success rate, resetting polling error count")
pollingErrorCount = 0
}
}
catch (e) {
log.error("Failed to poll actor", actor.getDisplayName(), e)
pollingErrorCount++
successCount = 0
log.error("Failed to poll actor", actor.getDisplayName(), "Error Count: " + pollingErrorCount, e)

if (pollingErrorCount > (5 * actors.length)) {
log.error("Too many polling errors, restarting service")
process.exit(1)
}
}
}

Expand Down

0 comments on commit 5ba74ed

Please sign in to comment.