Flask Task Monitor module
Project description
A flask plugin to monitor thread task
How to use
Install
To install from source, download the source code, then run this:
python setup.py install
Or install with pip:
pip install Flask-Task-Monitor
Setup
Adding the extension to your Flask app is simple:
from flask import Flask
from flask_monitor import Monitor
monitor = Monitor(config={
'FLASK_MONITOR_PERIOD': 1
})
app = Flask(__name__)
monitor.init_app(app)
Add monitered task with database
from flask_monitor import DBMonitor
from yourapplication import monitor
class DemoMonitorJob(DBMonitor):
def __init__(self, a, b, c):
super(DemoMonitorJob, self).__init__()
pass
@classmethod
def redo(cls, *args, **kwargs):
'''
execute when your job is crashed
'''
pass
@classmethod
def roll_back(cls, *args, **kwargs):
'''
execute after redo when catch exception
'''
pass
def do(self, *args, **kwargs):
'''your own job which needs to monitered
'''
pass
monitor.add_check_monitor(DemoMonitorJob)
Your own monitor
You can code your own monitor by redis, zookeeper, etcd and more
from flask_monitor import BaseMonitorInterface
class YourMonitor(BaseMonitorInterface):
def lock(self, *args, **kwargs):
'''
when called your do function
'''
pass
def unlock(self, args, **kwargs):
'''
when your do function return
'''
pass
@classmethod
def check(cls, *args, **kwargs):
'''
your own check function: it will return to
try:
redo(list, dict)
except Expection:
rollback(list,dict)
'''
return list, dict
@abstractmethod
def do(self, *args, **kwargs):
pass
@classmethod
@abstractmethod
def redo(self, *args, **kwargs):
pass
@classmethod
@abstractmethod
def rollback(self, *args, **kwargs):
pass
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
Flask-Task-Monitor-2.0.tar.gz
(72.2 kB
view details)
File details
Details for the file Flask-Task-Monitor-2.0.tar.gz.
File metadata
- Download URL: Flask-Task-Monitor-2.0.tar.gz
- Upload date:
- Size: 72.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49fc844943c64f2716d71bd1170ce572e213ee1cf4bf011407e6abdfce2f3968
|
|
| MD5 |
22a7113122467b7395ead6d81950c21d
|
|
| BLAKE2b-256 |
c8580de6a71cc3f3309d1cc27cb0fef4bfb963f5bd8212d213d4ccf0d0d7d652
|