-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: migrate job.ts to TypeScript
BREAKING CHANGE: `CronJob`'s constructor no longer accepts an object as its first and only param. Use `CronJob.from(argsObject)` instead. BREAKING CHANGE: removed `cron.job()` method in favor of `new CronJob()` / `CronJob.from()`
- Loading branch information
Showing
5 changed files
with
146 additions
and
307 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,17 @@ | ||
import { spawn } from 'child_process'; | ||
import * as luxon from 'luxon'; | ||
import { DateTime } from 'luxon'; | ||
import { CronTime } from './time'; | ||
import { CronCommand } from './types/interfaces'; | ||
|
||
export { CronJob } from './job'; | ||
export { CronTime } from './time'; | ||
export const CronJob = require('./job')(CronTime, spawn); | ||
|
||
export const job = ( | ||
cronTime: string | Date | luxon.DateTime, | ||
onTick: () => void, | ||
onComplete?: CronCommand | null, | ||
start?: boolean, | ||
timeZone?: string, | ||
context?: any, | ||
runOnInit?: boolean, | ||
utcOffset?: string | number, | ||
unrefTimeout?: boolean | ||
): typeof CronJob => | ||
new CronJob( | ||
cronTime, | ||
onTick, | ||
onComplete, | ||
start, | ||
timeZone, | ||
context, | ||
runOnInit, | ||
utcOffset, | ||
unrefTimeout | ||
); | ||
export const time = ( | ||
source: string | Date | DateTime, | ||
zone?: string, | ||
utcOffset?: string | number | ||
): CronTime => new CronTime(source, zone, utcOffset); | ||
|
||
export const time = (cronTime, timeZone) => new CronTime(cronTime, timeZone); | ||
export const sendAt = (cronTime: string | Date | DateTime): DateTime => | ||
exports.time(cronTime).sendAt(); | ||
|
||
export const sendAt = cronTime => exports.time(cronTime).sendAt(); | ||
|
||
export const timeout = cronTime => exports.time(cronTime).getTimeout(); | ||
export const timeout = (cronTime: string | Date | DateTime): number => | ||
exports.time(cronTime).getTimeout(); |
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
Oops, something went wrong.