Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ron-chang/flask_dbpacemaker
To keep long term connection with databse. this module is based on flask-sqlalchemy and Flask-APScheduler.
https://github.com/ron-chang/flask_dbpacemaker
apscheduler flask python3 sqlalchemy-database
Last synced: 15 days ago
JSON representation
To keep long term connection with databse. this module is based on flask-sqlalchemy and Flask-APScheduler.
- Host: GitHub
- URL: https://github.com/ron-chang/flask_dbpacemaker
- Owner: Ron-Chang
- License: mit
- Created: 2020-04-12T10:07:07.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-12-30T12:57:14.000Z (almost 3 years ago)
- Last Synced: 2024-11-15T06:29:03.569Z (about 1 month ago)
- Topics: apscheduler, flask, python3, sqlalchemy-database
- Language: Python
- Homepage: https://pypi.org/project/Flask-DBPacemaker/
- Size: 27.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask Database Pacemaker
```
tzlocal==2.1
python_requires>=3.6
Flask>=1.0.2
Flask-APScheduler>=1.11.0
Flask-SQLAlchemy>=2.3.2
```## - Log
|#| date|version|
|-|----------|-------|
|5|2020/12/07| v1.3.2|
|4|2020/12/07| v1.2.7|
|3|2020/12/05| v1.2.5|
|2|2020/12/03| v1.2.4|
|1|2020/12/03| v1.2.3|#### v1.3.2
- Fixed `pytz` `normalize` and `zone` deprecation warning.#### v1.2.3
- Fixed `AttributeError: 'NoneType' object has no attribute 'items'` issue due to mysql connection has been terminated.#### v1.2.4
- Handle `sqlalchemy.exc.ProgrammingError`, the problem cause by some specific ORM models not exist in current database.
- Handle database not found issue.
- Raise error if `MODELS_PATH_LIST` has not been set properly.#### v1.2.5
- Replace new line of the error raise from sqlalchemy.
- Change datetime format method.
- Make the code efficient.#### v1.2.7
- Add validation, testing awake() before assign the job to APScheduler.## - How to use
#### 1. Add setting into config.py
- `DB_PACEMAKER_SWITCH` __is required__
- `MODELS_PATH_LIST` __is required__
- `POKE_DB_INTERVAL` default: 1 hour.```python
# for DBPacemaker - 透過定時排程請求DB,保持連線
DB_PACEMAKER_SWITCH = True if os.environ['ENVIRONMENT'] == 'develop' else False
MODELS_PATH_LIST = ['spyder_common.models']
POKE_DB_INTERVAL = 60 * 60
```#### 2. Establish in `app.py`
>Note: Append this after you declared `config` and `app````python
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_dbpacemaker import DBPacemaker # import package
from config import Configapp = Flask(__name__)
config = Config()
app.config.from_object(config)db = SQLAlchemy(app)
DBPacemaker.run(app, db=db, config=config) # setup here
```- If you've set a scheduler
```python
DBPacemaker.run(app, db=db, config=config, secheduler=your_flask_apscheduler)
```_Note: The job permanent trigger is `interval`._
If you like my work, please consider buying me a coffee or [PayPal](https://paypal.me/RonDevStudio?locale.x=zh_TW)
Thanks for your support! Cheers! 🎉