rq / rq-scheduler

A lightweight library that adds job scheduling capabilities to RQ (Redis Queue)
MIT License
1.44k stars 230 forks source link

Schedulers taking longer than defined for execution #221

Open jangster3794 opened 4 years ago

jangster3794 commented 4 years ago

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)

spetoolio commented 4 years ago

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.

jangster3794 commented 4 years ago

@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.

spetoolio commented 4 years ago

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