From d8ad061ad75eaa3a9fb0a078d93aa404abf5ba9f Mon Sep 17 00:00:00 2001 From: Gaurav Kumar Date: Thu, 6 Nov 2025 17:53:05 +0530 Subject: [PATCH] cron job second --- .../cron-job-builder.component.html | 13 +++- .../cron-job-builder.component.ts | 62 ++++++++++++++----- 2 files changed, 56 insertions(+), 19 deletions(-) diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/Data_lake/cron-job-builder/cron-job-builder.component.html b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/Data_lake/cron-job-builder/cron-job-builder.component.html index d8df94d..f70c8a4 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/Data_lake/cron-job-builder/cron-job-builder.component.html +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/Data_lake/cron-job-builder/cron-job-builder.component.html @@ -1,6 +1,15 @@

Cron Job Builder

+
+
+ + +
+
+
@@ -28,7 +37,7 @@
-
+
diff --git a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/Data_lake/cron-job-builder/cron-job-builder.component.ts b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/Data_lake/cron-job-builder/cron-job-builder.component.ts index b00c59c..61f87a1 100644 --- a/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/Data_lake/cron-job-builder/cron-job-builder.component.ts +++ b/frontend/angular-clarity-master/src/app/modules/main/builder/dashboardnew/Data_lake/cron-job-builder/cron-job-builder.component.ts @@ -10,7 +10,8 @@ export class CronJobBuilderComponent implements OnInit, OnChanges { @Input() instanceId: string = ''; // Unique identifier for each instance @Output() cronExpressionChange = new EventEmitter(); - // Cron job fields + // Cron job fields (now starting with seconds) + second: string = '*'; minute: string = '*'; hour: string = '*'; dayOfMonth: string = '*'; @@ -21,6 +22,7 @@ export class CronJobBuilderComponent implements OnInit, OnChanges { cronDescription: string = ''; // Options for selectors + secondOptions: any[] = []; minuteOptions: any[] = []; hourOptions: any[] = []; dayOfMonthOptions: any[] = []; @@ -29,9 +31,10 @@ export class CronJobBuilderComponent implements OnInit, OnChanges { ngOnInit() { // Initialize options for each instance - this.minuteOptions = this.generateOptions(0, 59); - this.hourOptions = this.generateOptions(0, 23); - this.dayOfMonthOptions = this.generateOptions(1, 31); + this.secondOptions = this.generateOptions(0, 59, 'second'); + this.minuteOptions = this.generateOptions(0, 59, 'minute'); + this.hourOptions = this.generateOptions(0, 23, 'hour'); + this.dayOfMonthOptions = this.generateOptions(1, 31, 'day'); this.monthOptions = [ { value: '*', label: 'Every month' }, { value: '1', label: 'January' }, @@ -73,8 +76,8 @@ export class CronJobBuilderComponent implements OnInit, OnChanges { } } - generateOptions(start: number, end: number): any[] { - const options = [{ value: '*', label: `Every (${start === 0 ? '0' : start}-${end})` }]; + generateOptions(start: number, end: number, type: string): any[] { + const options = [{ value: '*', label: `Every ${type} (${start === 0 ? '0' : start}-${end})` }]; for (let i = start; i <= end; i++) { options.push({ value: i.toString(), label: i.toString() }); } @@ -83,7 +86,16 @@ export class CronJobBuilderComponent implements OnInit, OnChanges { parseCronExpression(expression: string) { const parts = expression.split(' '); - if (parts.length >= 5) { + if (parts.length >= 6) { // Now expecting 6 parts with seconds + this.second = parts[0]; + this.minute = parts[1]; + this.hour = parts[2]; + this.dayOfMonth = parts[3]; + this.month = parts[4]; + this.dayOfWeek = parts[5]; + } else if (parts.length >= 5) { // For backward compatibility with 5-part cron expressions + // Default seconds to 0 if not provided + this.second = '0'; this.minute = parts[0]; this.hour = parts[1]; this.dayOfMonth = parts[2]; @@ -95,19 +107,33 @@ export class CronJobBuilderComponent implements OnInit, OnChanges { generateDescription() { let description = 'Runs '; + // Second description + if (this.second === '*') { + description += 'every second'; + } else if (this.second.includes('/')) { + const interval = this.second.split('/')[1]; + description += `every ${interval} seconds`; + } else { + description += `at second ${this.second}`; + } + // Minute description if (this.minute === '*') { - description += 'every minute'; + if (this.second === '*') { + description += ''; + } else { + description += ' of every minute'; + } } else if (this.minute.includes('/')) { const interval = this.minute.split('/')[1]; - description += `every ${interval} minutes`; + description += ` of every ${interval} minutes`; } else { - description += `at minute ${this.minute}`; + description += ` at minute ${this.minute}`; } // Hour description if (this.hour === '*') { - if (this.minute === '*') { + if (this.minute === '*' && this.second === '*') { description += ''; } else { description += ' past every hour'; @@ -146,21 +172,23 @@ export class CronJobBuilderComponent implements OnInit, OnChanges { } // Special case for simple patterns - if (this.minute === '0' && this.hour === '0' && this.dayOfMonth === '1' && this.month === '*' && this.dayOfWeek === '*') { + if (this.second === '0' && this.minute === '0' && this.hour === '0' && this.dayOfMonth === '1' && this.month === '*' && this.dayOfWeek === '*') { description = 'Runs at midnight on the first day of every month'; - } else if (this.minute === '0' && this.hour === '0' && this.dayOfMonth === '*' && this.month === '*' && this.dayOfWeek === '*') { + } else if (this.second === '0' && this.minute === '0' && this.hour === '0' && this.dayOfMonth === '*' && this.month === '*' && this.dayOfWeek === '*') { description = 'Runs at midnight every day'; - } else if (this.minute === '0' && this.hour === '*' && this.dayOfMonth === '*' && this.month === '*' && this.dayOfWeek === '*') { + } else if (this.second === '0' && this.minute === '0' && this.hour === '*' && this.dayOfMonth === '*' && this.month === '*' && this.dayOfWeek === '*') { description = 'Runs at the top of every hour'; - } else if (this.minute === '*' && this.hour === '*' && this.dayOfMonth === '*' && this.month === '*' && this.dayOfWeek === '*') { - description = 'Runs every minute'; + } else if (this.second === '0' && this.minute === '*' && this.hour === '*' && this.dayOfMonth === '*' && this.month === '*' && this.dayOfWeek === '*') { + description = 'Runs at the top of every minute'; + } else if (this.second === '*' && this.minute === '*' && this.hour === '*' && this.dayOfMonth === '*' && this.month === '*' && this.dayOfWeek === '*') { + description = 'Runs every second'; } this.cronDescription = description; } buildCronExpression() { - const expression = `${this.minute} ${this.hour} ${this.dayOfMonth} ${this.month} ${this.dayOfWeek}`; + const expression = `${this.second} ${this.minute} ${this.hour} ${this.dayOfMonth} ${this.month} ${this.dayOfWeek}`; this.cronExpressionChange.emit(expression); this.generateDescription(); // Update description when expression changes return expression;