-
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
Feature: simplified closing of old db connections #170
Comments
Would this achieve the same result and perhaps be easier to understand (untested)? import functools
from apscheduler.schedulers.blocking import BlockingScheduler
from django import db
class BlockingDBScheduler(BlockingScheduler):
@util.close_old_connections
def add_job(self, func, *args, **kwargs):
# Edited to swap `wrapper` with `func` as per the correction pointed out by @HeyHugo in the comments below.
return super().add_job(func, *args, **kwargs) |
@jcass77 Aha nice yes that works (just swap |
Ok. I think this approach could be handy for folks who only intend to schedule jobs that always read or mutate the database. The drawback is that if you use something like I'm happy to leave this here for others to find and use in their projects if their use case is narrowly defined along the lines discussed above though. Thanks for pointing this out and providing a coding example! |
Ok that's fair and I agree. I have not yet had a case with a scheduled task without db interaction, but I understand there could be such use cases where state lives elsewhere. |
Hi, I'm a new user and this is what I want - connection management. This is why I search for such integrations:
And the most important thing is connection management. You just install it and use out of box - this is exactly what was expected from django batteries. About overhead: it's a cron-like solution. If someone needs very huge load with a lot of tasks, they should use Celery/Dramatiq/FastStream/... |
I'm using a customised
BlockingScheduler
class to ensure db connections are closed before/after running tasks.This simplifies things for me in two ways:
close_old_connections
decorator to my tasksclose_old_connections
decorator otherwise breaking my tests by prematurely closing the db connection my test session is using.It looks like this
If you'd think this class would fit as a part of the package I could make a PR, or if you think it'd be a nice addition to the docs as an alternative to the
@close_old_connections
-decorator I look at that as well.The text was updated successfully, but these errors were encountered: