fix(core): update
This commit is contained in:
parent
36bff0a70a
commit
db92311daa
@ -44,6 +44,17 @@ tap.test('should create a valid cronJon', async (tools) => {
|
|||||||
await done2.promise;
|
await done2.promise;
|
||||||
await done3.promise;
|
await done3.promise;
|
||||||
testCronManager.stop();
|
testCronManager.stop();
|
||||||
|
testCronManager.removeCronjob(cronJob3);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('runs every full minute', async (tools) => {
|
||||||
|
const done = tools.defer();
|
||||||
|
const cronJob = testCronManager.addCronjob('0 * * * * *', async () => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
testCronManager.start();
|
||||||
|
await done.promise;
|
||||||
|
testCronManager.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -27,7 +27,7 @@ export class CronParser {
|
|||||||
};
|
};
|
||||||
return findEvenMatch(startValue);
|
return findEvenMatch(startValue);
|
||||||
}
|
}
|
||||||
if (parseInt(cronPart, 10)) {
|
if (parseInt(cronPart, 10) || cronPart === '0') {
|
||||||
const match = parseInt(cronPart, 10);
|
const match = parseInt(cronPart, 10);
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
@ -42,19 +42,36 @@ export class CronParser {
|
|||||||
const monthExpression = cronArray[4];
|
const monthExpression = cronArray[4];
|
||||||
const yearExpression = cronArray[5];
|
const yearExpression = cronArray[5];
|
||||||
|
|
||||||
const currentDate = new Date();
|
let currentDate = new Date();
|
||||||
const currentSecond = currentDate.getSeconds() + 1;
|
let currentSecond = currentDate.getSeconds() + 1;
|
||||||
const currentMinute = currentDate.getMinutes();
|
let currentMinute = currentDate.getMinutes();
|
||||||
const currentHour = currentDate.getHours();
|
let currentHour = currentDate.getHours();
|
||||||
const currentDay = currentDate.getDate();
|
let currentDay = currentDate.getDate();
|
||||||
const currentMonth = currentDate.getMonth();
|
let currentMonth = currentDate.getMonth();
|
||||||
const currentYear = currentDate.getFullYear();
|
let currentYear = currentDate.getFullYear();
|
||||||
|
|
||||||
const targetSecond = this.getNextPartMatch(secondExpression, currentSecond, 59);
|
const targetSecond = this.getNextPartMatch(secondExpression, currentSecond, 59);
|
||||||
|
if (targetSecond < currentSecond) {
|
||||||
|
currentMinute = (currentMinute + 1) % 59;
|
||||||
|
}
|
||||||
const targetMinute = this.getNextPartMatch(minuteExpression, currentMinute, 59);
|
const targetMinute = this.getNextPartMatch(minuteExpression, currentMinute, 59);
|
||||||
|
if (targetMinute < currentMinute) {
|
||||||
|
currentHour = (currentHour + 1) % 23;
|
||||||
|
}
|
||||||
const targetHour = this.getNextPartMatch(hourExpression, currentHour, 23);
|
const targetHour = this.getNextPartMatch(hourExpression, currentHour, 23);
|
||||||
|
if (targetHour < currentHour) {
|
||||||
|
currentDay = (currentDay + 1) % 30;
|
||||||
|
}
|
||||||
|
|
||||||
const targetDay = currentDay;
|
const targetDay = currentDay;
|
||||||
|
if (targetDay < currentDay) {
|
||||||
|
currentMonth = (currentMonth + 1) % 11;
|
||||||
|
}
|
||||||
|
|
||||||
const targetMonth = currentMonth;
|
const targetMonth = currentMonth;
|
||||||
|
if (targetMonth < currentMonth) {
|
||||||
|
currentYear = (currentYear + 1);
|
||||||
|
}
|
||||||
const targetYear = currentYear;
|
const targetYear = currentYear;
|
||||||
|
|
||||||
const targetDate = new Date(
|
const targetDate = new Date(
|
||||||
|
Loading…
Reference in New Issue
Block a user