-
Notifications
You must be signed in to change notification settings - Fork 98
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
django_apscheduler.models.DjangoJobExecution.MultipleObjectsReturned #156
Comments
Starting a scheduler as part of your Django application, even in the The scheduler should be started via a dedicated admin command instead. |
I'm also seeing this error and I am running it via a management command so there should be only one process running. Same call stack |
Looking at the code, the only way I can see that happening is if (a) the same ID is given to multiple jobs and / or (b) the system clock is changed so that jobs are persisted with the same runtime information. Can you provide more details of your specific use case? |
I have a single job that runs every 30 minutes. It then checks our database for upcoming events and sends out email reminders for events that are 1 day from now or 2 hours from now. Looking at the job executions table it looks like some of them end up in the 'started executing' state and are never marked finished. No idea if that has anything to do with hitting this error. I am happy to try to help diagnose this and I can see how hard it is to reproduce. |
Although annoying, this shouldn't cause duplicate records to be created. It would still be worth the effort to investigate the issue to understand why APScheduler is not firing the In terms of the duplicate entries, I have pushed commit f49c883 which adds a constraint at database level to ensure that unique Please check it out and report any changes here. |
I do have the same problem on Heroku. I see multiple (2 times) job executions. I saw recommendations to start project like -> python manage.py runserver --noreload, but I don't know how to add parameter on heroku server. |
Hey @jcass77 , we are hitting the same issue and will try out your commit, but would you be able to make a pypi release later on including that change? When using git pins we lose nice things like dependabot checks |
Sure, let my know if it works for you and I will cut a new release. |
I'm also getting this error on Heroku, has there been a fix for this?
|
For some reason on heroku host, the apscheduler, always double tasks. I did try to fix the problem, after a few days I start to use post requests on my webhook based on [Heroku Scheduler] |
Ran into this issue on our Kubernetes cluster as well. Found out it had to do with the deployment cycle. While it does return the error when multiple instances of the apscheduler are active it does seem to recover itself from the error. |
@jcass77 we have been running this for a month or so now in a production environment and haven't hit any issues, so I think this is good for a release! |
v0.6.1 has been released. This won't prevent If you are using Heroku or Kubernetes, you need to be sure that you only have one instance of the scheduler running (I'm not familiar with those platforms so can't offer any advice unfortunately). |
Oh I think I know what's going on. in But we aren't locking the In some similar race-y code, what we have done is "lock all objects, then reconfirm conditions". Here it feels like what we probably want to do is:
Since the idea here is that not only do we not want concurrent updates..... I think that locking the |
Running multiple schedulers that share the same job store is BadTM (at least until such time that APScheduler 4.0 is released). Right now it is an anti-pattern that we probably should not try to enable via complex locking behaviour. If you are running on Heroku, then this thread containing Heroku-specific instructions in the upstream APScheduler issue log might be of interest to help you avoid starting up multiple schedulers in different web workers. |
We currently use your package in AWS environment in our project. But during its usage we face problem with multiple DjangoJobExecution creation. It is probably about race condition when new container is created (during deploying).
Do you support such an activity?
We use setup_scheduler() (same body as your tutorial page) in django app ready() method.
Here is traceback:
The text was updated successfully, but these errors were encountered: