diff --git a/src/ingestion/services/dateService.ts b/src/ingestion/services/dateService.ts index 479a5dc..4afe7ba 100644 --- a/src/ingestion/services/dateService.ts +++ b/src/ingestion/services/dateService.ts @@ -1,41 +1,23 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable } from "@nestjs/common"; @Injectable() -export class DateService{ - - getCurrentTime24(): string { - const currentDate = new Date(); - const currentHour = currentDate.getHours(); - const currentMinute = currentDate.getMinutes(); - return `${currentHour}:${currentMinute}`; - } - - // Function to check if the current time is greater than 12 PM - isTimeGreaterThan12PM(timeString) { - const [hours, minutes] = timeString.split(':'); - const hour = parseInt(hours, 10); - const minute = parseInt(minutes, 10); - - // Check if it's past 12 PM (noon) - return hour > 12 || (hour === 12 && minute > 0); - } - - getCurrentTimeForCronSchedule(){ - let currentTime = this.getCurrentTime24() - if (this.isTimeGreaterThan12PM(currentTime)) { - // Convert to IST (add 5 hours and 30 minutes for the UTC+5:30 offset) - const [hours, minutes] = currentTime.split(':'); - // const hour = parseInt(hours, 10) + 5; - // const minute = parseInt(minutes, 10) + 30; +export class DateService { + getCurrentISTTime():Date { + const now = new Date(); + const istOffset = 330 * 60 * 1000; + + const currentISTTime = new Date(now.getTime() + istOffset); - console.log("Hours is:", hours); - console.log("Minutes is:",minutes); - let min = parseInt(minutes) + 2 - return [hours,min] - } else { - return currentTime + return currentISTTime; } - } + getCronExpression(currentISTTime: Date):string { + const hours = currentISTTime.getUTCHours(); + const minutes = currentISTTime.getUTCMinutes(); - -} \ No newline at end of file + const scheduledMinutes = (minutes + 9) % 60; + const scheduledHours = hours + Math.floor((minutes + 9) / 60); + const cronExpression = `0 ${scheduledMinutes} ${scheduledHours} * * ?`; + + return cronExpression; + } +} diff --git a/src/ingestion/services/nvsk-api/nvsk-api.service.ts b/src/ingestion/services/nvsk-api/nvsk-api.service.ts index 1c1cfe8..5bce259 100644 --- a/src/ingestion/services/nvsk-api/nvsk-api.service.ts +++ b/src/ingestion/services/nvsk-api/nvsk-api.service.ts @@ -5,7 +5,6 @@ import { UploadService } from "./../file-uploader-service"; import { Body, Injectable } from "@nestjs/common"; import axios from "axios"; import { IngestionDatasetQuery } from "src/ingestion/query/ingestionQuery"; -import { DateService } from "../dateService"; import { Request } from "express"; import { processorGroupSelectionForCloudService } from "./processorGroup.service"; const csv = require("csv-parser"); @@ -17,7 +16,6 @@ export class NvskApiService { private service: GenericFunction, private databaseService: DatabaseService, private httpService: HttpCustomService, - private dateService: DateService, private prgoupService: processorGroupSelectionForCloudService ) {} /* NVSK side implementations */ diff --git a/src/ingestion/services/nvsk-api/processorGroup.service.ts b/src/ingestion/services/nvsk-api/processorGroup.service.ts index aaad298..40b1b41 100644 --- a/src/ingestion/services/nvsk-api/processorGroup.service.ts +++ b/src/ingestion/services/nvsk-api/processorGroup.service.ts @@ -1,14 +1,20 @@ import { Injectable } from "@nestjs/common"; +import { DateService } from "../dateService"; @Injectable() export class processorGroupSelectionForCloudService { + constructor(private dateService:DateService){ + + } getProcessorGroupArrayForCloudStorage() { if (process.env.STORAGE_TYPE === "oracle") { + const currentDate:Date = this.dateService.getCurrentISTTime() + const cronExpr = this.dateService.getCronExpression(currentDate); return [ { processor_group_name: "Run_adapters", scheduled_at: "0 */7 * * * ?" }, { processor_group_name: "onestep_dataingestion_oracle", - scheduled_at: "0 */9 * * * ?", + scheduled_at: `${cronExpr}`, }, ]; } else if (process.env.STORAGE_TYPE == "local") {