Compare commits
2 commits
46f78fa563
...
429ddebf02
Author | SHA1 | Date | |
---|---|---|---|
429ddebf02 | |||
8497091309 |
7 changed files with 50 additions and 16 deletions
|
@ -8,15 +8,12 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- mongodb_vol:/data/db
|
- mongodb_vol:/data/db
|
||||||
- ./mongo-init-scripts/init.js:/docker-entrypoint-initdb.d/mongo-init.js
|
- ./mongo-init-scripts/init.js:/docker-entrypoint-initdb.d/mongo-init.js
|
||||||
environment:
|
|
||||||
- MONGO_INITDB_DATABASE=${MONGO_INITDB_DATABASE}
|
|
||||||
- MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
|
|
||||||
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
|
|
||||||
platform: linux/arm64/v8
|
platform: linux/arm64/v8
|
||||||
expose:
|
expose:
|
||||||
- 27017
|
- 27017
|
||||||
|
|
||||||
rabbitmq:
|
rabbitmq:
|
||||||
image: todorabbit:latest
|
image: kfda89/todorabbit:latest
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 5672:5672
|
- 5672:5672
|
||||||
|
@ -24,9 +21,6 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- rabbitmq_volume:/var/lib/rabbitmq
|
- rabbitmq_volume:/var/lib/rabbitmq
|
||||||
- ./rabbitmq-init-scripts/init.sh:/docker-entrypoint-initdb.d/init.sh
|
- ./rabbitmq-init-scripts/init.sh:/docker-entrypoint-initdb.d/init.sh
|
||||||
environment:
|
|
||||||
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
|
|
||||||
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
|
|
||||||
expose:
|
expose:
|
||||||
- 5672
|
- 5672
|
||||||
- 15672
|
- 15672
|
||||||
|
|
20
notification-service/Dockerfile
Normal file
20
notification-service/Dockerfile
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# Use the official Node.js 14 image as the base
|
||||||
|
FROM node:14
|
||||||
|
|
||||||
|
# Set the working directory in the container
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package.json and package-lock.json to the container
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install project dependencies
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# Copy the rest of the application code to the container
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Expose the port on which your Express app listens
|
||||||
|
EXPOSE 4000
|
||||||
|
|
||||||
|
# Start the application in development mode
|
||||||
|
CMD ["npm", "run", "dev"]
|
|
@ -4,7 +4,7 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "tsc && nodemon dist/main.js"
|
"dev": "node dist/main.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|
|
@ -4,11 +4,11 @@ import { MongoDbModel } from "./mongodb/MongoDb";
|
||||||
|
|
||||||
export class NotificationService {
|
export class NotificationService {
|
||||||
rabbitmq: RabbitMQ;
|
rabbitmq: RabbitMQ;
|
||||||
mongoModle: MongoDbModel;
|
mongoModel: MongoDbModel;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.rabbitmq = new RabbitMQ();
|
this.rabbitmq = new RabbitMQ();
|
||||||
this.mongoModle = new MongoDbModel();
|
this.mongoModel = new MongoDbModel();
|
||||||
this.startListener();
|
this.startListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,11 +20,11 @@ export class NotificationService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async newMessageValidator(message: ITodo) {
|
async newMessageValidator(message: ITodo) {
|
||||||
const todo = await this.mongoModle.getTodoById(message._id.toString());
|
const todo = await this.mongoModel.getTodoById(message._id.toString());
|
||||||
if (todo) {
|
if (todo) {
|
||||||
const due_date = new Date(todo.due_date);
|
const due_date = new Date(todo.due_date);
|
||||||
if (todo.status === "pending" && due_date > new Date()) {
|
if (todo.status === "pending" && due_date > new Date()) {
|
||||||
await this.mongoModle.updateTodoStatus(todo);
|
await this.mongoModel.updateTodoStatus(todo);
|
||||||
await this.sendNotification(todo); // Send notification to user
|
await this.sendNotification(todo); // Send notification to user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
20
todo-service/Dockerfile
Normal file
20
todo-service/Dockerfile
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# Use the official Node.js 14 image as the base
|
||||||
|
FROM node:14
|
||||||
|
|
||||||
|
# Set the working directory in the container
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package.json and package-lock.json to the container
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install project dependencies
|
||||||
|
RUN npm install
|
||||||
|
|
||||||
|
# Copy the rest of the application code to the container
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Expose the port on which your Express app listens
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Start the application in development mode
|
||||||
|
CMD ["npm", "run", "dev"]
|
|
@ -4,7 +4,7 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon dist/main.js"
|
"dev": "node dist/main.js"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|
|
@ -58,7 +58,7 @@ export class RabbitMQ {
|
||||||
headers: { "x-delay": delayTimeForQueue },
|
headers: { "x-delay": delayTimeForQueue },
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
await this.channel.publish(
|
this.channel.publish(
|
||||||
this.exchange,
|
this.exchange,
|
||||||
this.queue,
|
this.queue,
|
||||||
Buffer.from(message),
|
Buffer.from(message),
|
||||||
|
@ -73,6 +73,6 @@ export class RabbitMQ {
|
||||||
|
|
||||||
calculateDelayTimeForQueue(payload: ITodo) {
|
calculateDelayTimeForQueue(payload: ITodo) {
|
||||||
const delayTime = payload.due_date.getTime() - Date.now();
|
const delayTime = payload.due_date.getTime() - Date.now();
|
||||||
return 0;
|
return delayTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue