Skip to main content

cherrypy server for Flask + task scheduler and monitor

Project description

Cherrypy prod server for Flask + parallel task scheduler

Python 3.6 license pytest

Installation

pip install flask_production

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)

# Run on end of every month (with strict_date False)
sched.every("31st").strict_date(False).at("08:00").do(foo)

# Run 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)

TaskMonitor Plugin

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
TaskMonitor uses these features to provide a web interface to view and rerun tasks
from flask import Flask
from flask_production import CherryFlask, TaskScheduler
from flask_production.plugins import TaskMonitor

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

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

# Run every minute
sched.every(60).do(foo)

cherry = CherryFlask(app, scheduler=sched)
cherry.run(host="0.0.0.0", port=8080) # localhost:8080/@taskmonitor

Example Gist here

Project details


Download files

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

Source Distribution

flask_production-2.5.4.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

flask_production-2.5.4-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file flask_production-2.5.4.tar.gz.

File metadata

  • Download URL: flask_production-2.5.4.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for flask_production-2.5.4.tar.gz
Algorithm Hash digest
SHA256 a8da6bb476115c817c22969891435d49d8b2f4d5ae23efc81f0d4836755288e2
MD5 870c0657123128b49f9d71a80a7e00b3
BLAKE2b-256 97229233fe20445474db30d120a08ccc522f407add3143ddbec3fb7a886f0312

See more details on using hashes here.

File details

Details for the file flask_production-2.5.4-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_production-2.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 705a535235d20ec2857c51e7d83327ac8221af10b7063f9a1ceda67f9fd9d52f
MD5 a9aa209cc2a2338d0d99ce8bcd13a117
BLAKE2b-256 fa13d053079744b76d961a221ab69b8db150550e8918088b9ec679896d231ad1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page