Add a scheduler to the Flask application

master
Pierre Jaury 8 years ago
parent d4f93e39db
commit c9aff0691b

@ -9,6 +9,8 @@ import flask_babel
import os import os
import docker import docker
from apscheduler.schedulers import background
# Create application # Create application
app = flask.Flask(__name__, static_url_path='/admin/app_static') app = flask.Flask(__name__, static_url_path='/admin/app_static')
@ -41,6 +43,7 @@ login_manager = flask_login.LoginManager()
login_manager.init_app(app) login_manager.init_app(app)
babel = flask_babel.Babel(app) babel = flask_babel.Babel(app)
translations = list(map(str, babel.list_translations())) translations = list(map(str, babel.list_translations()))
scheduler = background.BackgroundScheduler()
# Manager commnad # Manager commnad
manager = flask_script.Manager(app) manager = flask_script.Manager(app)
@ -49,6 +52,10 @@ manager.add_command('db', flask_migrate.MigrateCommand)
# Connect to the Docker socket # Connect to the Docker socket
dockercli = docker.Client(base_url=app.config['DOCKER_SOCKET']) dockercli = docker.Client(base_url=app.config['DOCKER_SOCKET'])
# Task scheduling
if not app.debug or os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
scheduler.start()
# Babel configuration # Babel configuration
@babel.localeselector @babel.localeselector
def get_locale(): def get_locale():
@ -60,4 +67,5 @@ app.register_blueprint(admin.app, url_prefix='/admin')
@app.route("/") @app.route("/")
def index(): def index():
return 1/0
return flask.redirect(flask.url_for("admin.index")) return flask.redirect(flask.url_for("admin.index"))

@ -12,3 +12,4 @@ passlib
gunicorn gunicorn
docker-py docker-py
tabulate tabulate
apscheduler

@ -1,5 +1,7 @@
from mailu import app import os
if __name__ == "__main__": if __name__ == "__main__":
app.run(debug=True) os.environ["DEBUG"] = "true"
from mailu import app
app.run()

Loading…
Cancel
Save