-
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.
Merge pull request #8 from emanguy/add-health-check
Add health check
- Loading branch information
Showing
13 changed files
with
345 additions
and
1,001 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 |
---|---|---|
|
@@ -2,4 +2,5 @@ build/ | |
node_modules/ | ||
.idea/ | ||
.env | ||
**/*.js | ||
**/*.js | ||
yarn-error.log |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {Response, Router} from "express"; | ||
import redisServiceRetriever from "../services/RedisUpdaterService"; | ||
import config from "../config"; | ||
import * as asyncHandler from "express-async-handler"; | ||
import {WinstonRequest} from "../middleware/logging-metadata"; | ||
import * as HttpStatus from "http-status-codes"; | ||
|
||
const healthRestController = Router(); | ||
const redisService = redisServiceRetriever(config); | ||
|
||
healthRestController.get("/", asyncHandler(async (req: WinstonRequest, res: Response) => { | ||
const connected = await redisService.sendTestMessage(); | ||
|
||
if (connected) { | ||
res.sendStatus(HttpStatus.OK); | ||
} else { | ||
res.sendStatus(HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
})); | ||
|
||
export default healthRestController; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
export interface RedisTestPayload { | ||
testValue: number; | ||
} | ||
|
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,48 @@ | ||
import * as Docker from "dockerode"; | ||
import {ContainerCreateOptions} from "dockerode"; | ||
import {Configuration} from "../src/config"; | ||
|
||
interface HostPortBinding { | ||
HostPort: string | ||
} | ||
|
||
interface CreateOptionsWithPortBindings extends ContainerCreateOptions { | ||
PortBindings: { | ||
[key: string]: HostPortBinding[] | ||
} | ||
} | ||
|
||
const redisPort = "6379"; | ||
|
||
export const testConfig: Configuration = { | ||
applicationPort: 3000, | ||
redisUrl: `redis://localhost:${redisPort}`, | ||
environment: "testing", | ||
redisPassword: "testRedis" | ||
}; | ||
|
||
export function createRedisContainer(docker: Docker): Promise<Docker.Container> { | ||
return docker.createContainer(<CreateOptionsWithPortBindings>{ | ||
Image: "bitnami/redis:4.0.9", | ||
Env: [ | ||
`REDIS_PASSWORD=${testConfig.redisPassword}` | ||
], | ||
PortBindings: { | ||
"6379/tcp": [{HostPort: redisPort}] | ||
} | ||
}); | ||
} | ||
|
||
export function pullRedisImage(docker: Docker): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
docker.pull("bitnami/redis:4.0.9", {}, (err, stream) => { | ||
if (err) { | ||
console.log("Got an error pulling the image."); | ||
reject(err); | ||
return; | ||
} | ||
|
||
docker.modem.followProgress(stream, (err?: Error) => err ? reject(err) : resolve(), () => {}); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.