This repository has been archived by the owner on Dec 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added healthcheck and updated dependencies
- Loading branch information
Freek Mencke
committed
Mar 23, 2019
1 parent
688c470
commit e54d2e4
Showing
11 changed files
with
584 additions
and
405 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
language: node_js | ||
language: minimal | ||
dist: trusty | ||
node_js: '10' | ||
|
||
cache: npm | ||
services: | ||
- docker | ||
|
||
script: | ||
- npm run lint | ||
- npm run build:ci | ||
|
||
- docker build --rm -t toxsickcoder/osrs-tracker-cron:dev . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
FROM node:10-alpine as builder | ||
WORKDIR /usr/src/app/ | ||
COPY package.json package-lock.json ./ | ||
RUN npm ci | ||
COPY . . | ||
RUN npm run lint | ||
RUN npm run build:ci | ||
|
||
FROM node:10-alpine | ||
WORKDIR /usr/src/app | ||
COPY ./dist . | ||
CMD ["node", "osrs-tracker-cron.js"] | ||
WORKDIR /usr/app/ | ||
COPY --from=builder /usr/src/app/dist/ ./ | ||
HEALTHCHECK --interval=1m --timeout=2s \ | ||
CMD wget --quiet --tries=1 --spider http://localhost:8080 || exit 1 | ||
CMD [ "node", "osrs-tracker-cron.js" ] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import http from 'http'; | ||
import { API } from '../../config/api'; | ||
import { HealthRepository } from '../repositories/health.repository'; | ||
import { Tasks } from '../tasks'; | ||
|
||
export function startHealthCheckServer(): void { | ||
http | ||
.createServer(async (req, res) => { | ||
const tasksRunning = | ||
Tasks.runningTasks.length === Tasks.TASK_COUNT && Tasks.runningTasks.reduce((a, b) => a && b.running!, true); | ||
|
||
let mysqlConnectionHealthy = false; | ||
await API.getDbConnection(connection => | ||
HealthRepository.checkConnection(connection).then(res => (mysqlConnectionHealthy = res.success)) | ||
); | ||
|
||
if (tasksRunning && mysqlConnectionHealthy) { | ||
res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
res.end('HEALTHY\n'); | ||
} else { | ||
res.writeHead(500, { 'Content-Type': 'text/plain' }); | ||
res.end('UNHEALTHY\n'); | ||
} | ||
}) | ||
.listen(8080); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { PoolConnection } from 'mysql'; | ||
|
||
export class HealthRepository { | ||
static checkConnection(connection: PoolConnection): Promise<{ success: boolean }> { | ||
return new Promise(resolve => connection.query('show tables', outerError => resolve({ success: !outerError }))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters