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

Cron is not scheduling as per the provided string

Open dhamechavivek95 opened this issue 4 years ago • 1 comments

@selwin I have my schedule.py file

from redis import Redis
from rq_scheduler import Scheduler
from my_file import My_Function

def run():
    r = Redis()
    scheduler = Scheduler(connection=r)

    scheduler.cron("0 * * * *", func=My_Function,
                   queue_name=My_Queue_Name)

Now in my_file.py

from dateTime import dateTime, timedelta

def My_Function():

    try:

        Logger.log.warning("$" * 40)

        from_time = \
            int(datetime.timestamp(datetime.now() - timedelta(hours=2)))
        to_time = int(datetime.timestamp(datetime.now() - timedelta(hours=1)))

        Logger.log.warning("Email")
        Logger.log.warning("From Time")
        Logger.log.warning(from_time)
        Logger.log.warning("To Time")
        Logger.log.warning(to_time)

It runs exactly 22 times in an hour at 10:31 and 10:32 and within a difference of seconds. I have my script in production, Please help me with this.

dhamechavivek95 avatar Apr 17 '20 06:04 dhamechavivek95

@dhamechavivek95 TTBOMK this is caused due to duplication of jobs. The problem is that previously scheduled jobs were run when you restarted your scheduler / worker.

I had faced the same problem, check out the solution given by @ipmb here - https://github.com/rq/rq-scheduler/issues/51#issuecomment-362352497

It basically subclasses rqscheduler and first clears the previous jobs and then registers new one's

backtrackbaba avatar Sep 07 '20 22:09 backtrackbaba