lykmapipo / kue-scheduler

A job scheduler utility for kue, backed by redis and built for node.js
246 stars 47 forks source link

Job runs immediately upon startup, and then resumes regular schedule #78

Closed nlabhart closed 7 years ago

nlabhart commented 7 years ago

Is there a way to have it not run as soon as the job is instantiated? Code below.

const kue = require( 'kue-scheduler' ); const moment = require( 'moment' ); const momentTz = require( 'moment-timezone' ); const config = require( './../config.js' );

var Queue = kue.createQueue( {
    redis: 'redis://rediscloud:2Ksqgw93K2rIyjXL@redis-16229.c8.us-east-1-4.ec2.cloud.redislabs.com:16229'
    , skipConfig: true
} );

Queue.clear(function(error,response) {
    console.log('Clearing redis data.');
    if (error) {
        console.log('error ' + error);
    }
    else {
        console.log(response);
    }
});

var jobInvoiceCompanies = Queue
            .createJob( 'invoiceCompanies', { timezone: 'America/Monterrey', title: 'Generate data to invoice companies with payment type of EDI.' } )
            .priority('normal')
            .unique( 'invoiceCompanies' )
            .save();

var jobBgCheckStatusAndUpdate = Queue
            .createJob( 'bgCheckStatusAndUpdate', { timezone: 'America/Monterrey', title: 'Check BG Check Status and Update Operator Reqs' } )
            .priority('normal')
            .unique( 'bgCheckStatusAndUpdate' )
            .save();

//schedule it to run on Sundays at midnight
Queue.every( '0 0 * * 7', jobInvoiceCompanies );

//schedule it to run every hour at the 59th minute
Queue.every( '10 seconds', jobBgCheckStatusAndUpdate );

Queue.process( 'invoiceCompanies', ( job, done ) => {
        //code to run here
});

Queue.process( 'bgCheckStatusAndUpdate', function( job, done ) {
        //code to run here
});
gmcnaught commented 7 years ago

Yes,

with Queue.every(), there is no need for .save().

On Wed, Jan 25, 2017 at 6:20 PM, Noah Labhart notifications@github.com wrote:

Is there a way to have it not run as soon as the job is instantiated? Code below.

const kue = require( 'kue-scheduler' ); const moment = require( 'moment' ); const momentTz = require( 'moment-timezone' ); const config = require( './../config.js' );

var Queue = kue.createQueue( { redis: 'redis://rediscloud:2Ksqgw93K2rIyjXL@redis-16229.c8.us-east-1-4.ec2.cloud.redislabs.com:16229' , skipConfig: true } );

Queue.clear(function(error,response) { console.log('Clearing redis data.'); if (error) { console.log('error ' + error); } else { console.log(response); } });

var jobInvoiceCompanies = Queue .createJob( 'invoiceCompanies', { timezone: 'America/Monterrey', title: 'Generate data to invoice companies with payment type of EDI.' } ) .priority('normal') .unique( 'invoiceCompanies' ) .save();

var jobBgCheckStatusAndUpdate = Queue .createJob( 'bgCheckStatusAndUpdate', { timezone: 'America/Monterrey', title: 'Check BG Check Status and Update Operator Reqs' } ) .priority('normal') .unique( 'bgCheckStatusAndUpdate' ) .save();

//schedule it to run on Sundays at midnight Queue.every( '0 0 7', jobInvoiceCompanies );

//schedule it to run every hour at the 59th minute Queue.every( '10 seconds', jobBgCheckStatusAndUpdate );

Queue.process( 'invoiceCompanies', ( job, done ) => { //code to run here });

Queue.process( 'bgCheckStatusAndUpdate', function( job, done ) { //code to run here });

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lykmapipo/kue-scheduler/issues/78, or mute the thread https://github.com/notifications/unsubscribe-auth/ABTsfzh07gU5VRsgOtnluNjLGhRSbQbvks5rV9jHgaJpZM4LuH75 .

nlabhart commented 7 years ago

Thanks @gmcnaught. That worked for this issue.

But now I'm having a separate one - the jobs are being called twice upon running. Any ideas there?

lykmapipo commented 7 years ago

@nlabhart

Check you schedule data for inconcistency. And make sure to separate you development and production deployment runs.