src dir, adaptations
All checks were successful
Build and publish farmacia-bot images / Build and push client's image to Gitea's registry (push) Successful in 17s
Build and publish farmacia-bot images / deploy_ovh (push) Successful in 23s

This commit is contained in:
Giancarmine Salucci 2025-04-15 17:37:27 +02:00
parent 15a2d61ed9
commit 24c99c2d58
6 changed files with 21 additions and 15 deletions

View File

@ -1,2 +1,4 @@
logs/
node_modules/
node_modules/
dist/
.gitea/

View File

@ -1,15 +1,18 @@
FROM node:23-alpine
WORKDIR /home/node
USER node
WORKDIR /home/node
RUN mkdir -p app/logs && chown -R node:node app
WORKDIR /home/node/app
COPY --chown=node:node package*.json ./
RUN npm install
COPY --chown=node:node main.js util.js worker.js ./
# Expose logs directory as a volume
COPY --chown=node:node src ./
VOLUME ["/home/node/app/logs"]
# Use an environment variable for thread count (default to 0 to use auto)
ENV THREAD_COUNT=0
# Run the application - using JSON array format
CMD ["sh", "-c", "node main.js ${THREAD_COUNT}"]

View File

@ -1,14 +1,15 @@
{
"name": "multithreaded-http-app",
"name": "bot-farmacia",
"version": "1.0.0",
"description": "A multithreaded Node.js app that performs repeated HTTP POST requests using worker threads.",
"main": "main.js",
"main": "src/main.js",
"output": "bot-farmacia.exe",
"scripts": {
"start": "node main.js",
"start:single": "node main.js 1",
"start:quad": "node main.js 4",
"start:octa": "node main.js 8"
"start": "node src/main.js",
"start:single": "node src/main.js 1",
"start:quad": "node src/main.js 4",
"start:octa": "node src/main.js 8"
},
"dependencies": {
"axios": "^1.6.0"

View File

@ -6,7 +6,7 @@ let totalSuccess = 0;
let totalError = 0;
const startTime = Date.now();
const logsDir = path.join(__dirname, 'logs');
const logsDir = 'logs';
if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir);
}
@ -28,7 +28,7 @@ module.exports = {
onMessage = ({ id, payload }) => console.log("onMessage", id, payload),
onError = ({ id, error }) => console.error("onError", id, error),
onExit = ({ id, status }) => console.log("onExit", id, status)) => {
return new Worker('./worker.js', { workerData })
return new Worker(path.join(__dirname, 'worker.js'), { workerData })
.on('message', (payload) => onMessage({ id: workerData.id, payload }))
.on('error', (error) => onError({ id: workerData.id, error }))
.on('exit', (status) => onExit({ id: workerData.id, status }));

View File

@ -1,4 +1,4 @@
const {workerFactory, onMessage, onError, onExit, logger} = require('./util');
const {workerFactory, onMessage, onError, onExit, logger} = require('./bot-util');
const os = require('os');
let THREAD_COUNT = Math.max(1, os.cpus().length - 1);;