Skip to content

Commit

Permalink
fix: Allow H range in cron expression for periodic builds (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranav Ravichandran authored Feb 20, 2019
1 parent f1d196f commit 19cecf0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ const transformCron = (cronExp, jobId) => {

const jobIdHash = stringHash(jobId.toString());

if (fields[0] !== 'H' && !fields[0].match(/H\(\d+-\d+\)/)) {
fields[0] = 'H';
}

// Minutes [0-59]
// Always treat the minutes value as 'H'
fields[0] = transformValue('H', 0, 59, jobIdHash);
fields[0] = transformValue(fields[0], 0, 59, jobIdHash);
// Hours [0-23]
fields[1] = transformValue(fields[1], 0, 23, jobIdHash);
// Day of month [1-31]
Expand Down
5 changes: 5 additions & 0 deletions test/lib/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ describe('cron', () => {
cronExp = '* H(0-5) * * *';
assert.deepEqual(cron.transform(cronExp, jobId),
`${minutesHash} ${evaluateHash(jobId, 0, 5)} * * *`);

// H(0-5) * * * *
cronExp = 'H(0-5) * * * *';
assert.deepEqual(cron.transform(cronExp, jobId),
`${evaluateHash(jobId, 0, 5)} * * * *`);
});

it('should throw if the cron expression has an invalid range value', () => {
Expand Down

0 comments on commit 19cecf0

Please sign in to comment.