@types/cron

  • Version 2.0.1
  • Published
  • 12 kB
  • 2 dependencies
  • MIT license

Install

npm i @types/cron
yarn add @types/cron
pnpm add @types/cron

Overview

TypeScript definitions for cron

Index

Functions

function job

job: {
(options: CronJobParameters): CronJob;
(
cronTime: any,
onTick: () => void,
onComplete?: CronCommand,
start?: boolean,
timeZone?: string,
context?: any,
runOnInit?: boolean,
utcOffset?: string | number,
unrefTimeout?: boolean
): CronJob;
};

    function sendAt

    sendAt: (cronTime: string | Date | DateTime) => DateTime;

      function time

      time: (source: string | Date | DateTime, zone?: string) => CronTime;

        function timeout

        timeout: (cronTime: string | Date | DateTime) => number;

          Classes

          class CronJob

          class CronJob {}

            constructor

            constructor(
            cronTime: any,
            onTick: CronCommand,
            onComplete?: CronCommand,
            startNow?: boolean,
            timeZone?: string,
            context?: any,
            runOnInit?: boolean,
            utcOffset?: string | number,
            unrefTimeout?: boolean
            );
            • Create a new ```CronJob```.

              Parameter cronTime

              The time to fire off your job. This can be in the form of cron syntax or a JS ```Date``` object.

              Parameter onTick

              The function to fire at the specified time.

              Parameter onComplete

              A function that will fire when the job is complete, when it is stopped.

              Parameter startNow

              Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call ```job.start()``` in order to start the job (assuming ```job``` is the variable you set the cronjob to). This does not immediately fire your onTick function, it just gives you more control over the behavior of your jobs.

              Parameter timeZone

              Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. Can be any string accepted by luxon's ```DateTime.setZone()``` (https://moment.github.io/luxon/api-docs/index.html#datetimesetzone).

              Parameter context

              The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call ```this.stop()```. However, if you change this you'll have access to the functions and values within your context object.

              Parameter runOnInit

              This will immediately fire your ```onTick``` function as soon as the requisit initialization has happened. This option is set to ```false``` by default for backwards compatibility.

              Parameter utcOffset

              This allows you to specify the offset of your timezone rather than using the ```timeZone``` param. Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.

              Parameter unrefTimeout

              If you have code that keeps the event loop running and want to stop the node process when that finishes regardless of the state of your cronjob, you can do so making use of this parameter. This is off by default and cron will run as if it needs to control the event loop. For more information take a look at [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref) from the NodeJS docs.

            constructor

            constructor(options: CronJobParameters);
            • Create a new ```CronJob```.

              Parameter options

              Job parameters.

            property fireOnTick

            fireOnTick: Function;
            • Function using to fire ```onTick```, default set to an inner private function. Overwrite this only if you have a really good reason to do so.

            property running

            running: boolean;
            • Return ```true``` if job is running.

            method addCallback

            addCallback: (callback: Function) => void;
            • Add another ```onTick``` function.

              Parameter callback

              Target function.

            method lastDate

            lastDate: () => Date;
            • Tells you the last execution date.

            method nextDate

            nextDate: () => DateTime;
            • Tells you when a ```CronTime``` will be run.

            method nextDates

            nextDates: { (): DateTime; (i?: number): any };
            • Tells you when a ```CronTime``` will be run.

              Parameter i

              Indicate which turn of run after now. If not given return next run time.

              Returns

              A DateTime when the cronTime passed in the constructor is a Date or a DateTime and an array of DateTime when the cronTime is a string.

            method setTime

            setTime: (time: CronTime) => void;
            • Change the time for the ```CronJob```.

              Parameter time

              Target time.

            method start

            start: () => void;
            • Runs your job.

            method stop

            stop: () => void;
            • Stops your job.

            class CronTime

            class CronTime {}

              constructor

              constructor(source: any, zone?: string, utcOffset?: string | number);
              • Create a new ```CronTime```.

                Parameter source

                The time to fire off your job. This can be in the form of cron syntax, a JS ```Date``` object, or a luxon ```DateTime``` object.

                Parameter zone

                Timezone name. Can be any string accepted by luxon's ```DateTime.setZone()``` (https://moment.github.io/luxon/api-docs/index.html#datetimesetzone).

                Parameter utcOffset

                UTC offset. Don't use both ```zone``` and ```utcOffset``` together or weird things may happen.

              method getTimeout

              getTimeout: () => number;
              • Get the number of milliseconds in the future at which to fire our callbacks.

              method sendAt

              sendAt: { (): DateTime; (i?: number): any };
              • Tells you when ```CronTime``` will be run.

              • Tells you when ```CronTime``` will be run.

                Parameter i

                Indicate which turn of run after now. If not given return next run time.

                Returns

                A ```DateTime``` when the source passed in the constructor is a ```Date``` or a ```DateTime``` and an array of ```DateTime``` when the source is a string.

              Interfaces

              interface CronJobParameters

              interface CronJobParameters {}

                property context

                context?: any;
                • The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call ```this.stop()```. However, if you change this you'll have access to the functions and values within your context object.

                property cronTime

                cronTime: string | Date | DateTime;
                • The time to fire off your job. This can be in the form of cron syntax, a JS ```Date``` object, or a luxon ```DateTime``` object.

                property onComplete

                onComplete?: CronCommand | null | undefined;
                • A function that will fire when the job is stopped with ```job.stop()```, and may also be called by ```onTick``` at the end of each run.

                property onTick

                onTick: CronCommand;
                • The function to fire at the specified time. If an ```onComplete``` callback was provided, ```onTick``` will receive it as an argument. ```onTick``` may call ```onComplete``` when it has finished its work.

                property runOnInit

                runOnInit?: boolean | undefined;
                • This will immediately fire your ```onTick``` function as soon as the requisit initialization has happened. This option is set to ```false``` by default for backwards compatibility.

                property start

                start?: boolean | undefined;
                • Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call ```job.start()``` in order to start the job (assuming ```job``` is the variable you set the cronjob to). This does not immediately fire your ```onTick``` function, it just gives you more control over the behavior of your jobs.

                property timeZone

                timeZone?: string | undefined;
                • Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. Can be any string accepted by luxon's ```DateTime.setZone()``` (https://moment.github.io/luxon/api-docs/index.html#datetimesetzone). Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.

                property unrefTimeout

                unrefTimeout?: boolean | undefined;
                • If you have code that keeps the event loop running and want to stop the node process when that finishes regardless of the state of your cronjob, you can do so making use of this parameter. This is off by default and cron will run as if it needs to control the event loop. For more information take a look at [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref) from the NodeJS docs.

                property utcOffset

                utcOffset?: string | number | undefined;
                • This allows you to specify the offset of your timezone rather than using the ```timeZone``` param. Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.

                Type Aliases

                type CronCommand

                type CronCommand =
                | (() => void)
                | string
                | {
                command: string;
                args?: ReadonlyArray<string> | undefined;
                options?: SpawnOptions | undefined;
                };

                  Package Files (1)

                  Dependencies (2)

                  Dev Dependencies (0)

                  No dev dependencies.

                  Peer Dependencies (0)

                  No peer dependencies.

                  Badge

                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/cron.

                  • Markdown
                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/cron)
                  • HTML
                    <a href="https://www.jsdocs.io/package/@types/cron"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>