• WEENIE FUNCTION - Returns a dependency that can be used to register and/or kill cronjobs

    Note that if this dependecy is used in conjunction with weenie's serviceManager, it will kill all cronjobs on SIGINT and SIGTERM (if the serviceManager is configured to handle those signals).

    Cronjobs should return true on success. They may return false on failure or throw an error. If they throw an error, the error will be logged and the cronjob will be considered to have failed. Returning false may be preferable as it gives you a little more control over how you log and communicate errors.

    Note that you may wish to use a retry strategy (such as the ones provided by the Weenie framework) to retry cronjobs on failure.

    Parameters

    Returns {
        cron: Cron;
    }

    Example

    import { cron } from '@wymp/weenie-cron';
    import { Weenie, logger, serviceManager } from '@wymp/weenie-framework';
    import { config } from './config';

    const deps = Weenie({ config })
    .and(logger)
    .and(serviceManager)
    .and(cron)
    .done((d) => d);

    deps.cron.register({
    name: 'my-cronjob',
    spec: '0 0 * * *',
    handler: async (log) => {
    log.info('Running my cronjob');
    return true;
    },
    'America/New_York'
    });

    deps.svc.declareReady();

Generated using TypeDoc