Skip to main content

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

This version

2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Flask-Task-Monitor, version 2.0
Filename, size File type Python version Upload date Hashes
Filename, size Flask-Task-Monitor-2.0.tar.gz (72.2 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page