@types/cron

  • Version 1.7.2
  • Published
  • 11.6 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 | Moment) => any;

      function time

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

        function timeout

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

          Classes

          class CronJob

          class CronJob {}

            constructor

            constructor(
            cronTime: any,
            onTick: CronCommand,
            onComplete?: CronCommand,
            start?: 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 start

              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. You can check all timezones available at [Moment Timezone Website](http://momentjs.com/timezone/).

              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: () => any;
            • Tells you when a ```CronTime``` will be run.

            method nextDates

            nextDates: { (): any; (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 Moment when the cronTime passed in the constructor is a Date or a Moment and an array of Moment 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 or a JS ```Date``` object.

                Parameter zone

                Timezone name. You can check all timezones available at [Moment Timezone Website](http://momentjs.com/timezone/).

                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: { (): any; (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 Moment when the source passed in the constructor is a Date or a Moment and an array of Moment 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 | Moment;
                • The time to fire off your job. This can be in the form of cron syntax or a JS ```Date``` object.

                property onComplete

                onComplete?: CronCommand | null;
                • 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;
                • 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;
                • 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;
                • 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. You can check all timezones available at [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use both ```timeZone``` and ```utcOffset``` together or weird things may happen.

                property unrefTimeout

                unrefTimeout?: boolean;
                • 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;
                • 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>; options?: SpawnOptions };

                  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>