rq-scheduler icon indicating copy to clipboard operation
rq-scheduler copied to clipboard

Periodic Job - Not respecting interval and repeat parameters

Open igorbpf opened this issue 8 years ago • 17 comments

I set a code similar to the example in the README to be executed repeatedly. Interval=5 and repeat=10, but rq-scheduler is not executing jobs at this rate. Does anyone know how to solve this?

igorbpf avatar Feb 24 '17 01:02 igorbpf

What rate is your scheduler executing the jobs at? I set the interval to 3600, hoping that it would execute once every hour, but it's actually executing multiple times per second.

lukasklein avatar Apr 05 '17 09:04 lukasklein

Also having issues with scheduled jobs. I set interval to 3600 seconds but they're executed every 1m

marpada avatar Apr 08 '17 03:04 marpada

Any solution to this? I am having the same issue specifically with interval - regardless of what I set it gets executed every 1m, although repeat seems to be working.

msapoz avatar Apr 11 '17 20:04 msapoz

Im having the same issue @marpada . do yo have a solution for this?

ryanermita avatar Aug 01 '17 02:08 ryanermita

Any update on this problem ?

Ouradze avatar Oct 27 '17 10:10 Ouradze

@eclar #163 this might help.

ryanermita avatar Oct 27 '17 11:10 ryanermita

@ryanermita Thanks, I understand better now.

Ouradze avatar Oct 27 '17 14:10 Ouradze

Is this issue soled? I have set up 60sec scheduler refresh and task interval is one hour (interval=3600), but the task gets scheduled every minute and sometimes even twice a minute :(

nad2000 avatar Jun 11 '18 09:06 nad2000

I can confirm that repeat also gets ignored.

nad2000 avatar Jun 11 '18 09:06 nad2000

I've not seen this, so curious as to what's different about what you're doing...

cjw296 avatar Jun 13 '18 17:06 cjw296

I was trying to isolate the issue. I couldn't reproduce the issue. It might be something wrong with flask-rq2 integration with the scheduer....

nad2000 avatar Jun 14 '18 03:06 nad2000

It appears that decorator schedule create a scheduled task every time the flask app gets restarted. And you work in the development environment with reloading it happens often. I wonder if there is a way to control that. I tried with setting job_id. It resulted in the KeyError exception at the reloading.

nad2000 avatar Jun 14 '18 04:06 nad2000

Digging around I found that the working approach is to remove all scheduler jobs before setting up (https://stackoverflow.com/a/32033454/235362) schedule. With flask-rq2 it would be:


from . import tasks, rq
from datetime import datetime           

def setup():                                                                 
    """Set up the application schedule. Remove any already scheduled jobs."""
    scheduler = rq.get_scheduler()                                           
    for job in scheduler.get_jobs():                                         
        job.delete()                                                         

    # NB! add result_ttl! Otherwise it won't get rescheduled
    tasks.my_task.schedule(datetime.utcnow(), interval=3600, result_ttl=-1, job_id="*MY-TASK*"))

nad2000 avatar Jun 14 '18 05:06 nad2000

does it continue to happen if you pass an explicit job id?

kg-2 avatar Oct 29 '19 17:10 kg-2

UPDATE! NB! it turned out that if result_ttl needs to be provided. Otherwise, it won't get rescheduled and will get removed from the list of the scheduled tasks. So to set up the scheduled task, use this snippet:

from . import tasks, rq
from datetime import datetime           

def setup():                                                                 
    """Set up the application schedule. Remove any already scheduled jobs."""
    scheduler = rq.get_scheduler()                                           
    for job in scheduler.get_jobs():                                         
        job.delete()                                                         

    tasks.my_task.schedule(datetime.utcnow(), interval=3600, result_ttl=-1, job_id="*MY-TASK*")
``

nad2000 avatar Oct 30 '19 00:10 nad2000

Any update on this issue? Seems to be an obvious problem, but it's been open for more than 2 years. This issue has been bugging my team a lot too.

kevinisaac avatar Jan 07 '20 10:01 kevinisaac

using cron strings worked well for me

kg-2 avatar Jan 12 '20 16:01 kg-2