Skip to content

Commit

Permalink
Merge pull request #295 from dhanush-2397/dev
Browse files Browse the repository at this point in the history
creating a cron expression for oracle
  • Loading branch information
dhanush-2397 authored Jan 31, 2024
2 parents 7e3a75f + fde0d56 commit 89a4ea7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 39 deletions.
54 changes: 18 additions & 36 deletions src/ingestion/services/dateService.ts
Original file line number Diff line number Diff line change
@@ -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();


}
const scheduledMinutes = (minutes + 9) % 60;
const scheduledHours = hours + Math.floor((minutes + 9) / 60);
const cronExpression = `0 ${scheduledMinutes} ${scheduledHours} * * ?`;

return cronExpression;
}
}
2 changes: 0 additions & 2 deletions src/ingestion/services/nvsk-api/nvsk-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 */
Expand Down
8 changes: 7 additions & 1 deletion src/ingestion/services/nvsk-api/processorGroup.service.ts
Original file line number Diff line number Diff line change
@@ -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") {
Expand Down

0 comments on commit 89a4ea7

Please sign in to comment.