cron job second
This commit is contained in:
@@ -1,6 +1,15 @@
|
|||||||
<div class="cron-job-builder">
|
<div class="cron-job-builder">
|
||||||
<h4>Cron Job Builder</h4>
|
<h4>Cron Job Builder</h4>
|
||||||
<div class="clr-row">
|
<div class="clr-row">
|
||||||
|
<div class="clr-col-lg-2 clr-col-md-4 clr-col-sm-6 clr-col-12">
|
||||||
|
<div class="form-group">
|
||||||
|
<label>Second</label>
|
||||||
|
<select class="form-control" [(ngModel)]="second" (change)="onFieldChange()">
|
||||||
|
<option *ngFor="let option of secondOptions" [value]="option.value">{{ option.label }}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="clr-col-lg-2 clr-col-md-4 clr-col-sm-6 clr-col-12">
|
<div class="clr-col-lg-2 clr-col-md-4 clr-col-sm-6 clr-col-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Minute</label>
|
<label>Minute</label>
|
||||||
@@ -28,7 +37,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="clr-col-lg-3 clr-col-md-6 clr-col-sm-6 clr-col-12">
|
<div class="clr-col-lg-2 clr-col-md-4 clr-col-sm-6 clr-col-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Month</label>
|
<label>Month</label>
|
||||||
<select class="form-control" [(ngModel)]="month" (change)="onFieldChange()">
|
<select class="form-control" [(ngModel)]="month" (change)="onFieldChange()">
|
||||||
@@ -37,7 +46,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="clr-col-lg-3 clr-col-md-6 clr-col-sm-12 clr-col-12">
|
<div class="clr-col-lg-2 clr-col-md-4 clr-col-sm-6 clr-col-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>Day of Week</label>
|
<label>Day of Week</label>
|
||||||
<select class="form-control" [(ngModel)]="dayOfWeek" (change)="onFieldChange()">
|
<select class="form-control" [(ngModel)]="dayOfWeek" (change)="onFieldChange()">
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ export class CronJobBuilderComponent implements OnInit, OnChanges {
|
|||||||
@Input() instanceId: string = ''; // Unique identifier for each instance
|
@Input() instanceId: string = ''; // Unique identifier for each instance
|
||||||
@Output() cronExpressionChange = new EventEmitter<string>();
|
@Output() cronExpressionChange = new EventEmitter<string>();
|
||||||
|
|
||||||
// Cron job fields
|
// Cron job fields (now starting with seconds)
|
||||||
|
second: string = '*';
|
||||||
minute: string = '*';
|
minute: string = '*';
|
||||||
hour: string = '*';
|
hour: string = '*';
|
||||||
dayOfMonth: string = '*';
|
dayOfMonth: string = '*';
|
||||||
@@ -21,6 +22,7 @@ export class CronJobBuilderComponent implements OnInit, OnChanges {
|
|||||||
cronDescription: string = '';
|
cronDescription: string = '';
|
||||||
|
|
||||||
// Options for selectors
|
// Options for selectors
|
||||||
|
secondOptions: any[] = [];
|
||||||
minuteOptions: any[] = [];
|
minuteOptions: any[] = [];
|
||||||
hourOptions: any[] = [];
|
hourOptions: any[] = [];
|
||||||
dayOfMonthOptions: any[] = [];
|
dayOfMonthOptions: any[] = [];
|
||||||
@@ -29,9 +31,10 @@ export class CronJobBuilderComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
// Initialize options for each instance
|
// Initialize options for each instance
|
||||||
this.minuteOptions = this.generateOptions(0, 59);
|
this.secondOptions = this.generateOptions(0, 59, 'second');
|
||||||
this.hourOptions = this.generateOptions(0, 23);
|
this.minuteOptions = this.generateOptions(0, 59, 'minute');
|
||||||
this.dayOfMonthOptions = this.generateOptions(1, 31);
|
this.hourOptions = this.generateOptions(0, 23, 'hour');
|
||||||
|
this.dayOfMonthOptions = this.generateOptions(1, 31, 'day');
|
||||||
this.monthOptions = [
|
this.monthOptions = [
|
||||||
{ value: '*', label: 'Every month' },
|
{ value: '*', label: 'Every month' },
|
||||||
{ value: '1', label: 'January' },
|
{ value: '1', label: 'January' },
|
||||||
@@ -73,8 +76,8 @@ export class CronJobBuilderComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generateOptions(start: number, end: number): any[] {
|
generateOptions(start: number, end: number, type: string): any[] {
|
||||||
const options = [{ value: '*', label: `Every (${start === 0 ? '0' : start}-${end})` }];
|
const options = [{ value: '*', label: `Every ${type} (${start === 0 ? '0' : start}-${end})` }];
|
||||||
for (let i = start; i <= end; i++) {
|
for (let i = start; i <= end; i++) {
|
||||||
options.push({ value: i.toString(), label: i.toString() });
|
options.push({ value: i.toString(), label: i.toString() });
|
||||||
}
|
}
|
||||||
@@ -83,7 +86,16 @@ export class CronJobBuilderComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
parseCronExpression(expression: string) {
|
parseCronExpression(expression: string) {
|
||||||
const parts = expression.split(' ');
|
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.minute = parts[0];
|
||||||
this.hour = parts[1];
|
this.hour = parts[1];
|
||||||
this.dayOfMonth = parts[2];
|
this.dayOfMonth = parts[2];
|
||||||
@@ -95,19 +107,33 @@ export class CronJobBuilderComponent implements OnInit, OnChanges {
|
|||||||
generateDescription() {
|
generateDescription() {
|
||||||
let description = 'Runs ';
|
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
|
// Minute description
|
||||||
if (this.minute === '*') {
|
if (this.minute === '*') {
|
||||||
description += 'every minute';
|
if (this.second === '*') {
|
||||||
|
description += '';
|
||||||
|
} else {
|
||||||
|
description += ' of every minute';
|
||||||
|
}
|
||||||
} else if (this.minute.includes('/')) {
|
} else if (this.minute.includes('/')) {
|
||||||
const interval = this.minute.split('/')[1];
|
const interval = this.minute.split('/')[1];
|
||||||
description += `every ${interval} minutes`;
|
description += ` of every ${interval} minutes`;
|
||||||
} else {
|
} else {
|
||||||
description += ` at minute ${this.minute}`;
|
description += ` at minute ${this.minute}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hour description
|
// Hour description
|
||||||
if (this.hour === '*') {
|
if (this.hour === '*') {
|
||||||
if (this.minute === '*') {
|
if (this.minute === '*' && this.second === '*') {
|
||||||
description += '';
|
description += '';
|
||||||
} else {
|
} else {
|
||||||
description += ' past every hour';
|
description += ' past every hour';
|
||||||
@@ -146,21 +172,23 @@ export class CronJobBuilderComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Special case for simple patterns
|
// 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';
|
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';
|
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';
|
description = 'Runs at the top of every hour';
|
||||||
} else if (this.minute === '*' && this.hour === '*' && this.dayOfMonth === '*' && this.month === '*' && this.dayOfWeek === '*') {
|
} else if (this.second === '0' && this.minute === '*' && this.hour === '*' && this.dayOfMonth === '*' && this.month === '*' && this.dayOfWeek === '*') {
|
||||||
description = 'Runs every minute';
|
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;
|
this.cronDescription = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildCronExpression() {
|
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.cronExpressionChange.emit(expression);
|
||||||
this.generateDescription(); // Update description when expression changes
|
this.generateDescription(); // Update description when expression changes
|
||||||
return expression;
|
return expression;
|
||||||
|
|||||||
Reference in New Issue
Block a user