-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed cronExpressionRepeatingEveryNMinutes
- fixed issue where cronExpressionRepeatingEveryNMinutes generated an expression that did not handle values larger than 60 properly
- Loading branch information
Showing
3 changed files
with
30 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
import { Minutes } from '../date/date'; | ||
import { Hours, Minutes } from '../date/date'; | ||
import { Maybe } from './maybe.type'; | ||
|
||
/** | ||
* A cron schedule expression string | ||
*/ | ||
export type CronExpression = string; | ||
|
||
export function cronExpressionRepeatingEveryNMinutes(minutes: Minutes): CronExpression { | ||
return `*/${minutes} * * * *`; // every nth minute | ||
/** | ||
* Creates a CronExpression for the input number of minutes. | ||
* | ||
* Note that if the number of minutes is greater than 60, it will generate an expression that | ||
* isn't exactly n number of minutes apart from the previous execution, but instead create | ||
* an expression that is n/60 hours apart and take place on the n%60th minute. | ||
* | ||
* @param inputMinutes | ||
* @returns | ||
*/ | ||
export function cronExpressionRepeatingEveryNMinutes(inputMinutes: Minutes): CronExpression { | ||
let minutes: Minutes; | ||
let hours: Maybe<Hours>; | ||
|
||
let expression: CronExpression; | ||
|
||
if (inputMinutes >= 60) { | ||
hours = Math.floor(inputMinutes / 60); | ||
minutes = inputMinutes % 60; | ||
|
||
expression = `${minutes} */${hours} * * *`; // every nth hour at the given minute | ||
} else { | ||
expression = `*/${inputMinutes} * * * *`; // every nth minute | ||
} | ||
|
||
return expression; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters