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

Schedulers taking longer than defined for execution

Open jangster3794 opened this issue 5 years ago • 3 comments

def schedule_task(func, delaytime=1, *args,**kwargs): enqueue_time = datetime.utcnow() + timedelta(seconds=delaytime) scheduler.enqueue_at(enqueue_time, delay_queue_handler, func, *args,**kwargs)

This is how I am trying to schedule my task. However, it takes more than 25-30 seconds before it sends my task to the worker.

What can I do to fix this?

Or if I am not approaching this well, please let me know

This is how my scheduler is initializing

scheduler = Scheduler('default',connection=redis_conn)

jangster3794 avatar Jan 06 '20 09:01 jangster3794

The scheduler only queues job on a certain interval. If your enqueue_time falls between intervals, it will not be added to the queue until the next interval (which will then be picked up by your worker). Look at https://github.com/rq/rq-scheduler#running-the-scheduler - specifically about the interval.

This may be what you're experiencing.

spetoolio avatar Jan 08 '20 20:01 spetoolio

@dfrank8 Hi, Thanks for replying. Can you please tell me the default interval? By what you have explained, I think this is exactly what's happening because if I have queued some tasks, all of them execute at the same time.

jangster3794 avatar Jan 09 '20 05:01 jangster3794

A quick look at the docs shows the default interval is 60.

https://github.com/rq/rq-scheduler/blob/master/rq_scheduler/scheduler.py#L26

spetoolio avatar Jan 09 '20 16:01 spetoolio