Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

active status to know when job is waiting for next tick or currently executing #308

Closed
ktravelet opened this issue Sep 15, 2017 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@ktravelet
Copy link

Hi All, first thanks a ton for this. I'm currently using it in a monitoring tool that goes and pulls SQL at set intervals. It seems to be working wonderfully.

I'm trying to prevent these jobs from overlapping and the method is not the most elegant. Right now I'm setting an active parameter to the this object and have an condition to catch if the job is currently executing.

Would it be possible to make something like this built in and is there better way to do it?

Thanks!

var job = new CronJob({
    cronTime: '* * * * * *',
    onTick: () => {

        if (typeof this.isCurrentlyExecuting === 'undefined') {

            this.isCurrentlyExecuting = false;

        }

        if (this.isCurrentlyExecuting) {

            console.log(moment().format('YYYY-MM-DD HH:mm:ss.SS - ') + 'Job already running.  Canceling this execution.', this);
            return;

        }

        this.isCurrentlyExecuting = true;

        console.log(moment().format('YYYY-MM-DD HH:mm:ss.SS - ') + 'Job is currently executing');

        setTimeout(()=>{

            console.log(moment().format('YYYY-MM-DD HH:mm:ss.SS - ') + 'Job is done executing');
            this.isCurrentlyExecuting = false;

        }, 5000)

    },
    start: true /* Start the job right now */
});

The code above will output the following:

2017-09-15 18:13:10.38 - Job is currently executing
2017-09-15 18:13:11.38 - Job already running.  Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:12.38 - Job already running.  Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:13.38 - Job already running.  Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:14.38 - Job already running.  Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:15.38 - Job is done executing
2017-09-15 18:13:15.38 - Job is currently executing
2017-09-15 18:13:16.38 - Job already running.  Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:17.38 - Job already running.  Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:18.38 - Job already running.  Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:19.38 - Job already running.  Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:20.38 - Job is done executing
@ncb000gt
Copy link
Member

I'd consider a PR but don't have the time to implement this kind of thing at the moment.

@sheerlox sheerlox added the type:feature New feature or feature improvement & requests label Sep 26, 2023
@sheerlox sheerlox reopened this Sep 26, 2023
@sheerlox sheerlox added Type: Feature Request type:feature New feature or feature improvement & requests and removed type:feature New feature or feature improvement & requests type:feature-request labels Sep 30, 2023
@sheerlox
Copy link
Collaborator

duplicate of #556

@sheerlox sheerlox closed this as not planned Won't fix, can't repro, duplicate, stale Sep 30, 2023
@sheerlox sheerlox added duplicate This issue or pull request already exists and removed type:feature New feature or feature improvement & requests labels Sep 30, 2023
@sheerlox sheerlox changed the title Feature Request / review process, active status to know when job is waiting for next tick or currently executing active status to know when job is waiting for next tick or currently executing Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants