feat(schedule): Support scheduling by weeks of year. (#3914)

Fixes #3879.
This commit is contained in:
Matt R. Wilson 2019-06-10 22:17:12 -06:00 committed by Rhys Arkins
parent 4ce426560c
commit 9212a876fc
2 changed files with 16 additions and 0 deletions

View file

@ -172,6 +172,10 @@ function isScheduledNow(config) {
return false;
}
}
// Check for week of year
if (schedule.wy && !schedule.wy.includes(now.week())) {
return false;
}
logger.debug(`Matches schedule ${scheduleText}`);
return true;
});

View file

@ -202,5 +202,17 @@ describe('workers/branch/schedule', () => {
const res = schedule.isScheduledNow(config);
expect(res).toBe(true);
});
it('approves valid weeks of year', () => {
config.schedule = ['every 2 weeks of the year before 08:00 on Monday'];
mockDate.set('2017-01-02T06:00:00.000'); // Locally Monday, 2 January 2017 6am (first Monday of the year)
const res = schedule.isScheduledNow(config);
expect(res).toBe(true);
});
it('rejects on weeks of year', () => {
config.schedule = ['every 2 weeks of the year before 08:00 on Monday'];
mockDate.set('2017-01-09T06:00:00.000'); // Locally Monday, 2 January 2017 6am (second Monday of the year)
const res = schedule.isScheduledNow(config);
expect(res).toBe(false);
});
});
});