Skip to content
Shashank Gopikrishna edited this page Oct 25, 2020 · 4 revisions

Welcome to the Flask_Production wiki!

Cherrypy prod server for Flask + parallel scheduler plugin

Python 3.6 license pytest

Installation (latest)

pip install -U git+https://github.com/shashfrankenstien/Flask_Production.git

Usage example

Cherrypy Server

from flask import Flask
from flask_production import CherryFlask

app = Flask(__name__)
cherry = CherryFlask(app)

cherry.run(host="0.0.0.0", port=8080, threads=5, debug=False)

Cherrypy Server + TaskScheduler

from flask import Flask
from flask_production import CherryFlask, TaskScheduler

app = Flask(__name__)

sched = TaskScheduler(check_interval=2)
# Run every minute
sched.every(60).do(foo)
# Runs on end of every month (with strict_date False)
sched.every("31st").strict_date(False).at("08:00").do(foo)
# Runs every weekday
sched.every("weekday").at("08:00").do(lambda:bar())
# catch() will run on job error
example_job = sched.every("weekday").at("09:00").do(lambda:failing()).catch(lambda e: print(e))

# access job information and status as dict
print(example_job.to_dict())
print(sched.jobs[-1].to_dict()) # same job

cherry = CherryFlask(app, scheduler=sched)
cherry.run(host="0.0.0.0", port=8080, threads=5, debug=False)

Experimental Plugins

The TaskScheduler exposes a list of Job objects through the .jobs attribute

Job information and logs from the last execution are available using the .to_dict() method

There is one example plugin ReadOnlyTaskMonitor

from flask import Flask
from flask_production import CherryFlask, TaskScheduler
from flask_production.plugins import ReadOnlyTaskMonitor

app = Flask(__name__)
sched = TaskScheduler(check_interval=2)

monitor = ReadOnlyTaskMonitor(app, sched)
print(monitor._endpoint) # /@taskmonitor

sched.every(60).do(foo) # Runs every minute
cherry = CherryFlask(app, scheduler=sched)
cherry.run(host="0.0.0.0", port=8080)
# localhost:8080/@taskmonitor

Example Gist here

Clone this wiki locally