apscheduler icon indicating copy to clipboard operation
apscheduler copied to clipboard

BackgroundScheduler is not working after few hours

Open Nayyaroddeen opened this issue 3 years ago • 5 comments

I am using the django to build a reminders service the current version of apscheduler=3.7.0

Issue: Scheduling and executing of jobs works fine for 10 hours of spinning the server. Post that we are able to add job but BackgroundScheduler is not able to execute the given function. I have enabled the logging but didn't find anything in logs

What could be the potential reason?

#creating a scheduler
scheduler = BackgroundScheduler(timezone=settings.TIME_ZONE)
scheduler.add_jobstore(DjangoJobStore(), "default")
if not scheduler.running:
    scheduler.start()

#adding job
 job = scheduler.add_job(send_reminder,
                                        trigger='date',
                                        next_run_time=str(date_time),
                                        args=[text])

#function to execute
def send_reminder(text, recruiter_id, company_id, application_id):
     print("something")

Nayyaroddeen avatar May 28 '21 17:05 Nayyaroddeen

I'm surprised this works at all, since there is nothing in this script to keep the background scheduler running and the script would just exit.

You also seem to be using an unofficial job store which may also be a problem.

agronholm avatar May 28 '21 18:05 agronholm

If you can give me a script that reproduces the problem using an official job store, I can investigate the problem.

agronholm avatar May 28 '21 18:05 agronholm

@agronholm yes, I copied parts of the script. I found there is an issue with threads flag --enable-threads for uWSGI https://apscheduler.readthedocs.io/en/latest/faq.html. I am experimenting with https://gunicorn.org/, logs are coming properly. I will update the ticket accordingly. Thank you.

Nayyaroddeen avatar May 28 '21 19:05 Nayyaroddeen

has the problem been solved? i had the same problem, and the log didn't have anything error or exception

jjqi92 avatar Aug 18 '21 04:08 jjqi92

It happens due to mysql server disconnection. were you able to check it?

Nayyaroddeen avatar Aug 18 '21 04:08 Nayyaroddeen