mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
refactor: move cron schedule logging (#30611)
This commit is contained in:
parent
8e97c90a36
commit
33d8d588c5
2 changed files with 26 additions and 25 deletions
|
@ -409,29 +409,30 @@ describe('workers/repository/update/branch/schedule', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('cronstrue', () => {
|
describe('log cron schedules', () => {
|
||||||
it('should correctly convert "0 22 4 * *" to human-readable format', () => {
|
it('should correctly convert "* 22 4 * *" to human-readable format', () => {
|
||||||
const result = cronstrue.toString('0 22 4 * *');
|
const result = cronstrue.toString('* 22 4 * *');
|
||||||
expect(result).toBe('At 10:00 PM, on day 4 of the month');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should correctly convert "*/2 * * * *" to human-readable format', () => {
|
|
||||||
const result = cronstrue.toString('*/2 * * * *');
|
|
||||||
expect(result).toBe('Every 2 minutes');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should correctly convert "0 23 * * *" to human-readable format', () => {
|
|
||||||
const result = cronstrue.toString('0 23 * * *');
|
|
||||||
expect(result).toBe('At 11:00 PM');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw an error for an invalid cron expression "* * */2 6#1"', () => {
|
|
||||||
const result = cronstrue.toString('* * */2 6#1', {
|
|
||||||
throwExceptionOnParseError: false,
|
|
||||||
});
|
|
||||||
expect(result).toBe(
|
expect(result).toBe(
|
||||||
'An error occured when generating the expression description. Check the cron expression syntax.',
|
'Every minute, between 10:00 PM and 10:59 PM, on day 4 of the month',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should correctly convert "* */2 * * *" to human-readable format', () => {
|
||||||
|
const result = cronstrue.toString('* */2 * * *');
|
||||||
|
expect(result).toBe('Every minute, every 2 hours');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should correctly convert "* 23 * * *" to human-readable format', () => {
|
||||||
|
const result = cronstrue.toString('* 23 * * *');
|
||||||
|
expect(result).toBe('Every minute, between 11:00 PM and 11:59 PM');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not throw an error for an invalid cron expression "* * */2 6#1"', () => {
|
||||||
|
expect(() => {
|
||||||
|
cronstrue.toString('* * */2 6#1', {
|
||||||
|
throwExceptionOnParseError: false,
|
||||||
|
});
|
||||||
|
}).not.toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,10 +26,6 @@ function parseCron(
|
||||||
timezone?: string,
|
timezone?: string,
|
||||||
): CronExpression | undefined {
|
): CronExpression | undefined {
|
||||||
try {
|
try {
|
||||||
const cronScheduleSummary = cronstrue.toString(scheduleText, {
|
|
||||||
throwExceptionOnParseError: false,
|
|
||||||
});
|
|
||||||
logger.debug(`Human-readable summary for cron:: ${cronScheduleSummary}`);
|
|
||||||
return parseExpression(scheduleText, { tz: timezone });
|
return parseExpression(scheduleText, { tz: timezone });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -203,6 +199,10 @@ export function isScheduledNow(
|
||||||
const isWithinSchedule = configSchedule.some((scheduleText) => {
|
const isWithinSchedule = configSchedule.some((scheduleText) => {
|
||||||
const cronSchedule = parseCron(scheduleText);
|
const cronSchedule = parseCron(scheduleText);
|
||||||
if (cronSchedule) {
|
if (cronSchedule) {
|
||||||
|
const cronScheduleSummary = cronstrue.toString(scheduleText, {
|
||||||
|
throwExceptionOnParseError: false,
|
||||||
|
});
|
||||||
|
logger.debug(`Human-readable summary for cron:: ${cronScheduleSummary}`);
|
||||||
// We have Cron syntax
|
// We have Cron syntax
|
||||||
if (cronMatches(scheduleText, now, config.timezone)) {
|
if (cronMatches(scheduleText, now, config.timezone)) {
|
||||||
logger.debug(`Matches schedule ${scheduleText}`);
|
logger.debug(`Matches schedule ${scheduleText}`);
|
||||||
|
|
Loading…
Reference in a new issue