Comments (4)
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)
from django-apscheduler.
@jcass77 Aha nice yes that works (just swap wrapper
arg to func
)
from django-apscheduler.
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 BlockingDBScheduler
for anything else then those extra calls to db.close_old_connections()
are essentially superfluous and just unnecessary overhead. That feels like an unreasonable tradeoff for the sake of convenience and syntactical sugar, and maybe not something that we want as the default behaviour for new users.
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!
from django-apscheduler.
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.
from django-apscheduler.
Related Issues (20)
- PytzUsageWarning on Startup HOT 3
- Missing migration
- Feat: Add management command to clean up job execution table HOT 2
- How to associate django_apscheduler_djangojob with my own model by ForeignKey HOT 1
- Job automatically disappeared in random time HOT 2
- Client number building up leading to fatal error HOT 1
- skipped: maximum number of running instances reached
- cron function that is running over 15 seconds is not working HOT 1
- DB error executing '_get_jobs' ((2013, 'Lost connection to MySQL server during query')). Retrying with a new DB connection... HOT 3
- Add @util.close_old_connections in the _get_jobs(self, **filters) funtion for the DB connection
- AttributeError("'zoneinfo.ZoneInfo' object has no attribute 'localize'") and 'dict' object has no attribute 'has_header'
- ModuleNotFoundError: No module named 'backports'
- how to forbid change_permission and delete_permission... HOT 2
- Scheduler goes idle or does not execute jobs at all HOT 1
- transaction.atomic() problem with DATABASE_ROUTERS HOT 2
- django-apscheduler (0.6.2) not working with psycopg2-binary (2.9.4 and up)
- Trigger scheduled job to be executed manually HOT 2
- Unapplying Migrations Fails
- DjangoJobStore Randomly Deletes Jobs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-apscheduler.