Skip to content

Commit

Permalink
dockerized stats service (not working)
Browse files Browse the repository at this point in the history
  • Loading branch information
iyanfdezz committed Mar 3, 2024
1 parent 8327b73 commit 14e0db2
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ services:
networks:
- mynetwork

statsservice:
container_name: statsservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1a/stats:latest
profiles: ["dev", "prod"]
build: ./stats
depends_on:
- mongodb
- userservice
ports:
- "8004:8004"
networks:
- mynetwork
environment:
MONGODB_URI: mongodb://mongodb:27017/userdb
USER_SERVICE_URL: http://userservice:8001

authservice:
container_name: authservice-${teamname:-defaultASW}
image: ghcr.io/arquisoft/wiq_es1a/authservice:latest
Expand Down Expand Up @@ -59,11 +75,13 @@ services:
- userservice
- authservice
- questionservice
- statsservice
ports:
- "8000:8000"
networks:
- mynetwork
environment:
STATS_SERVICE_URL: http://statsservice:8004
QUESTION_SERVICE_URL: http://questionservice:8003
AUTH_SERVICE_URL: http://authservice:8002
USER_SERVICE_URL: http://userservice:8001
Expand Down
2 changes: 2 additions & 0 deletions stats/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
20 changes: 20 additions & 0 deletions stats/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:20

# Set the working directory in the container
WORKDIR /usr/src/stats

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install app dependencies
RUN npm install

# Copy the app source code to the working directory
COPY . .

# Expose the port the app runs on
EXPOSE 8004

# Define the command to run your app
CMD ["node", "stats-service.js"]
3 changes: 2 additions & 1 deletion stats/model/stats-getter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const User = require('../../users/userservice/user-model.js/User');
const User = require('../../users/userservice/user-model.js');

class StatsForUser {

Expand All @@ -16,6 +16,7 @@ class StatsForUser {
var totalPoints = 0;
var totalCorrectQuestions = 0;
var totalIncorrectQuestions = 0;
var avgTime=0;

for (const partida of partidas){
totalPoints += partida.points;
Expand Down
19 changes: 3 additions & 16 deletions stats/stats-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const StatsForUser = require("./model/stats-getter");
const User = require("../users/user-model.js");
const cors = require('cors');

const cron = require("node-cron");

const app = express();
const port = 8004;

Expand Down Expand Up @@ -60,19 +58,8 @@ app.get("/stats", async (req, res) => {
}
});

const server = app.listen(port, async() => {
console.log(`Stats Service listening at http://localhost:${port}`);
statsGetter.getStatsForUser(req.query.user)
.then(() => {
console.log("Stats loaded successfully!");
})
.catch((error) => {
console.error("Error al cargar las estadísticas", error);
});
});

cron.schedule("0 3 * * *", async () => {
await statsGetter.getStatsForUser(req.query.user);
});
const server = app.listen(port, () => {
console.log(`Stats Service listening at http://localhost:${port}`);
});

module.exports = server;

0 comments on commit 14e0db2

Please sign in to comment.