Skip to content

Commit 872bff6

Browse files
committed
added start point demo
1 parent 7fba5d9 commit 872bff6

7 files changed

Lines changed: 445 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
*.md
3+
Dockerfile
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node:16-alpine
2+
3+
WORKDIR /opt/app
4+
5+
COPY . .
6+
7+
RUN npm ci
8+
9+
CMD ["npm", "start"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const getRandom = (start, end) => Math.floor((Math.random() * end) + start);
2+
3+
const randomBatchProcess = () => {
4+
const jobs = getRandom(50, 500);
5+
const failed = getRandom(1, 50);
6+
const processed = jobs - failed;
7+
return { jobs, failed, processed };
8+
};
9+
10+
module.exports.batch = () => {
11+
const intervalId = setInterval(() => {
12+
const { jobs, failed, processed } = randomBatchProcess();
13+
console.log(jobs, failed, processed);
14+
}, 5_000);
15+
16+
return intervalId;
17+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = ({
2+
port: +process.env.PORT || 3000,
3+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const express = require('express');
2+
const { port } = require('./config');
3+
const { batch } = require('./batch');
4+
5+
const intervalId = batch();
6+
const app = express();
7+
8+
app.get('/metrics', async (_, res) => {
9+
try {
10+
res.send('Not implemented yet');
11+
} catch (ex) {
12+
res.status(500).end(ex);
13+
}
14+
});
15+
16+
app.post('/stop', (_, res) => {
17+
clearInterval(intervalId);
18+
res.send('batch process stopped');
19+
});
20+
21+
app.listen(port, () => {
22+
console.log(`Listening at ${port}`);
23+
});

0 commit comments

Comments
 (0)