Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: recognice if the backend is broken #26

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/autoFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/heartbeat.ts
Original file line number Diff line number Diff line change
@@ -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
Loading