-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With django-apscheduler, some jobs are never executed due to connection timeout #13
Comments
Thanks for very detail explanation. I sure problem is about Mysql connection handling. Mysql closes connection which sleeps for a long time. I'll take a look today/tomorrow and try to solve it |
Fixed, release 0.2.5 available on Pypi: https://github.com/jarekwg/django-apscheduler/releases/tag/0.2.5 Please, check and if everything is ok I'm close the issue |
You are welcome. By the way, you can reproduce the issue by:
You may see the same error. Another thing is I agree that MySQL may close the connection, but setting the timeout on mysql side may not be a solution, because I may plannify a job in 7 days and... that is too long for timeout. |
I've just added "mysql gone away" exception handling, please update to 0.2.5 and check whether exception gone or not. And please, give feedback to me in order to close the issue. |
Wow, fixed! What did you added in the code? I see try-catch but did you reconnect DB in catch? |
It is a bit tricky solution: on every access to DjangoJob queryset I try to ping database (https://github.com/jarekwg/django-apscheduler/blob/master/django_apscheduler/models.py#L17). If ping fails I perform reconnect. Unfortunately, it works only for DjangoJob queries. But you can use this Manager class for any model you want to be protected from "Mysql has gone away" error. I don't know elegant way in Django to beat "Mysql has gone away" error for long-running scripts, only hand-written try-except blocks with reconnect. It is my pain in Django, because mostly I use mysql. Anyway, I glad exception dissapeared. Feel free to contact me with any other problems. |
Yeah.... I see your pain.. That is I think what is bad in python: it is useful for scripting, but if you want to use a script, it is your obligation to manage all the import and so on, to handle all the possible problems in a relatively isolated situation. I didn't expect your reply to be so quick, Thanks again! The code of reconnection is imprescindible for solving this. |
hello, I have the same problem. |
hi @sallyruthstruik you can write a decorator like below to handle the problem("mysql has gone away"):
and use this decorator like below:
I think it is an elegant way! |
I find that if I keep Apscheduler busy, i.e., keep adding jobs to it, it will stay happy and active. But, if I leave it without job for a time, say, 12 hours or more, and add job again, even it is running (
scheduler.state
returns1
, which isRUNNING
, when I consult with a web service), it accepts job, but does not execute it, when therun_date
arrives. I have configureddjango-apscheduler
as the jobstore.I am using APScheduler along with Apache and Django.
Yesterday, at 10:00 AM, I plannified three jobs, job A at 23:30 yesterday, job B at 09:00 today, and job C 09:50 today, and after that, I left the server there, no more jobs from yesterday from 1000 to 2330.
Checking the logs of yesterday, at 2330, this error happened:
And then, at 0900 and 0950, this error does not appear in log, and jobs not executed.
I think django-apscheduler should wake the connection to DB before it is going to execute the job, because at that moment, we cannot be sure if the connection is alive or not.
The text was updated successfully, but these errors were encountered: