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

config.waiting does not work #51

Open
wanyong117 opened this issue Jun 9, 2020 · 3 comments
Open

config.waiting does not work #51

wanyong117 opened this issue Jun 9, 2020 · 3 comments

Comments

@wanyong117
Copy link

For a task that may need to run more than 5 minutes, I set config.waiting :true as I wish that the scheduler will not schedule job when this job is running.
@Cron('*/5 * * * *', {
startTime: new Date(),
waiting : true,
})

But seems the configuration does not work, the job still is able to run, and two same jobs run at the same time.

@luizsandoval
Copy link

luizsandoval commented Jul 9, 2020

I am having the same problem. I have a job that needs to run every 5 minutes, but sometimes it takes more than that to finish, so I tried setting 'waiting' to true, but it doesn't seems to work.

Here is my code:
@Cron('0 */5 * * * *', { key: 'Keep Invoice Tasks', waiting: true, immediate: true }) async cronJob() {

Am I doing something wrong?

@svenmuellerssen
Copy link

svenmuellerssen commented Aug 20, 2020

Hi,
I use the current latest package version 0.6.4 and I ran into the same issue.
After some time of debugging I found several problems.

  1. In the latest version on NPM the property waiting does not work because the job status is set back from RUNNING to READY before the job starts. When the next job is triggered the status of the currently running job is READY instead of RUNNING so the next job will be executed.
    Fortunately there was a commit in the master branch that fixed the bug (fc7c894).
    Unfortunately the latest code on github is not the same than on NPM so the bug still exists on NPM.

  2. The next problem is the variable needStop

    if (needStop) {

If needStop is true the job is removed from the internal job list and will never reset at runtime.
The variable itself is set with the return value of the executed job method. This means that the job method itself has to return false to ensure running the cron job constantly.

I solved the problem by using Promise<boolean> in the job method with resolve(false) and reject(true).

@miaowing It would be very nice to build a new version for NPM based on your latest code on github. That fixes the bug. I did it with the sources and it worked :-)

@luizsandoval
Copy link

luizsandoval commented Oct 2, 2020

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants