From 850514719f9bffff7722d4614b814d25519382b0 Mon Sep 17 00:00:00 2001 From: AdriDevelopsThings Date: Wed, 6 Dec 2023 23:27:36 +0100 Subject: [PATCH 1/2] feat: recognice if the backend is broken --- src/autoFetch.ts | 5 ++--- src/heartbeat.ts | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/heartbeat.ts diff --git a/src/autoFetch.ts b/src/autoFetch.ts index 18671df..c59ac52 100644 --- a/src/autoFetch.ts +++ b/src/autoFetch.ts @@ -2,13 +2,12 @@ import { DateTime } from 'luxon' import { info, debug } from './logger.js' import { rabbit } from './rabbit/rabbit.js' import staticConfig from './staticConfig.js' -import fetch from 'node-fetch' +import heartbeat from './heartbeat.js' let fetchedHour: number | null = null export const autoFetch = () => { - if (process.env.HEARTBEAT_URL) - fetch(process.env.HEARTBEAT_URL) + heartbeat() const hour = DateTime.now().hour if (fetchedHour != hour) { fetchedHour = hour diff --git a/src/heartbeat.ts b/src/heartbeat.ts new file mode 100644 index 0000000..b6f6ae3 --- /dev/null +++ b/src/heartbeat.ts @@ -0,0 +1,25 @@ +import { DateTime } from 'luxon' +import fetch from 'node-fetch' +import database from './database.js' + +const runHeartbeat = async () => { + let heartbeatUrl = process.env.HEARTBEAT_URL + const newestTrainTrip = await database('train_trip').whereNotNull('destination_station').first() + + if (newestTrainTrip) { + const newestTrainTripHour = DateTime.now().diff(DateTime.fromJSDate(newestTrainTrip.timestamp)).as('hours') + if (newestTrainTripHour > 6) { + console.error('The newest train trip in the database is about 6 hours old. It seem\'s like the backend is broken. Try to restart.') + console.error('Heartbeat disabled because the backend seems to broken') + heartbeatUrl = undefined // disable heartbeat + } + } else { + console.warn('No full train trip does yet exist in the database') + } + + if (heartbeatUrl) { + fetch(heartbeatUrl) + } +} + +export default runHeartbeat \ No newline at end of file From 4a005087e5230cc18a87e3cd5ba69ebb4200e797 Mon Sep 17 00:00:00 2001 From: AdriDevelopsThings Date: Wed, 6 Dec 2023 23:29:35 +0100 Subject: [PATCH 2/2] fix: remove cosign from docker publish action --- .github/workflows/docker-publish.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 5ed2535..27e5716 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -31,15 +31,6 @@ jobs: - name: Checkout repository uses: actions/checkout@v2 - # Install the cosign tool except on PR - # https://github.com/sigstore/cosign-installer - - name: Install cosign - if: github.event_name != 'pull_request' - uses: sigstore/cosign-installer@1e95c1de343b5b0c23352d6417ee3e48d5bcd422 - with: - cosign-release: 'v1.4.0' - - # Workaround: https://github.com/docker/build-push-action/issues/461 - name: Setup Docker buildx uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf