From 739f3b991343bea5c90157f7671939734213aa9a Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Thu, 13 Jul 2023 11:19:22 +0300 Subject: [PATCH] fixing small bug --- notification-service/src/main.ts | 18 ++++++++++++++---- request.http | 2 +- todo-service/src/rabbitmq/RabbitMQ.ts | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/notification-service/src/main.ts b/notification-service/src/main.ts index 5db0e27..4ed2f0d 100644 --- a/notification-service/src/main.ts +++ b/notification-service/src/main.ts @@ -6,7 +6,7 @@ import { DateService } from "./services/DateService"; export class NotificationService { rabbitmq: RabbitMQ; mongoModel: MongoDbModel; - currentDate: any; + currentDate: DateService; constructor() { this.currentDate = DateService.getInstance(); @@ -20,6 +20,12 @@ export class NotificationService { if (this.IsUserConnected()) { await this.rabbitmq.connect(); this.rabbitmq.startConsumer(this.newMessageValidator.bind(this)); + } else { + // Retry in 5 seconds + setTimeout(() => { + console.log("Waiting for user to connect...") + this.startListener(); + }, 5000); } } @@ -28,13 +34,15 @@ export class NotificationService { const todo: ITodo | void = await this.mongoModel.getTodoById(message._id.toString()); if (todo) { const due_date = new Date(todo.due_date); - if (todo.status === "pending" && due_date > this.currentDate.getDate()) { + if (todo.status === "pending" && due_date > this.currentDate.getCurrentDate()) { await this.mongoModel.updateTodoStatus(todo); await this.sendNotification(todo); // Send notification to user } + } else { + console.error("todo Not found"); } - } catch { - console.error("todo Not found"); + } catch (error) { + console.error(error.message); } } @@ -46,3 +54,5 @@ export class NotificationService { console.log("Sending notification for Todo:", todo._id); } } + +new NotificationService(); diff --git a/request.http b/request.http index 0127d3b..06c3ddf 100644 --- a/request.http +++ b/request.http @@ -9,7 +9,7 @@ Content-Type: application/json { "title": "-2!!!!NEW!!!!", "description": "Go to the gym at 8pm", - "due_date": "2023-07-09T19:00:00.891Z" + "due_date": "2023-07-13T19:00:00.891Z" } ### update request diff --git a/todo-service/src/rabbitmq/RabbitMQ.ts b/todo-service/src/rabbitmq/RabbitMQ.ts index 59e16d1..14588c0 100644 --- a/todo-service/src/rabbitmq/RabbitMQ.ts +++ b/todo-service/src/rabbitmq/RabbitMQ.ts @@ -71,6 +71,6 @@ export class RabbitMQ { calculateDelayTimeForQueue(payload: ITodo) { const delayTime = payload.due_date.getTime() - this.currentDate.getCurrentDate().getTime(); - return delayTime; + return 0; } }