Hook db connection when you're running a long term sleep crawler assignment.
Project description
Flask Database Pacemaker
python_requires>=3.6
Flask>=1.0.2
Flask-APScheduler>=1.11.0
Flask-SQLAlchemy>=2.3.2
- Log
# | date | version |
---|---|---|
1 | 2020/12/03 | v1.2.2 |
v1.2.2
- Fixed
AttributeError: 'NoneType' object has no attribute 'items'
issue due to mysql connection has been terminated.
- How to use
1. Add setting into config.py
DB_PACEMAKER_SWITCH
is requiredMODELS_PATH_LIST
is requiredPOKE_DB_INTERVAL
default: 1 hour.
# 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
andapp
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_dbpacemaker import DBPacemaker # import package
from config import Config
app = 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
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 Thanks for your support! Cheers! 🎉
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file Flask-DBPacemaker-1.2.3.tar.gz
.
File metadata
- Download URL: Flask-DBPacemaker-1.2.3.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6681ec4ea4a600f692b2ad0a79dd43dfa7bcc9647b0e89035306ef289708b37 |
|
MD5 | e7f971d81942b3d1ad63b5529c2861f6 |
|
BLAKE2b-256 | 323dfbae79644f1dc8d1c6bcdcab650bb40b1e5a79bb69afbe466466540db5cc |