Add scheduler.

This commit is contained in:
Patrick Jentsch 2019-07-10 13:41:48 +02:00
parent 0158f5bedc
commit 9679ef80c8
4 changed files with 36 additions and 1 deletions

View File

@ -1,3 +1,4 @@
from apscheduler.schedulers.background import BackgroundScheduler
from config import config from config import config
from flask import Flask from flask import Flask
from flask_login import LoginManager from flask_login import LoginManager
@ -6,11 +7,14 @@ from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy() db = SQLAlchemy()
mail = Mail()
login_manager = LoginManager() login_manager = LoginManager()
login_manager.login_view = 'auth.login' login_manager.login_view = 'auth.login'
mail = Mail()
background_scheduler = BackgroundScheduler()
def create_app(config_name): def create_app(config_name):
app = Flask(__name__) app = Flask(__name__)
@ -27,4 +31,9 @@ def create_app(config_name):
from .main import main as main_blueprint from .main import main as main_blueprint
app.register_blueprint(main_blueprint) app.register_blueprint(main_blueprint)
from .scheduler import scheduler as scheduler_blueprint
app.register_blueprint(scheduler_blueprint, url_prefix='/scheduler')
background_scheduler.start()
return app return app

View File

@ -0,0 +1,5 @@
from flask import Blueprint
scheduler = Blueprint('scheduler', __name__)
from . import views

0
app/scheduler/forms.py Normal file
View File

21
app/scheduler/views.py Normal file
View File

@ -0,0 +1,21 @@
from flask import render_template
from . import scheduler
from flask_login import current_user, login_required
from .. import background_scheduler
import json
@scheduler.route('/')
@login_required
def schedule():
job = {
'creator': current_user.id,
'files': ['file_1', 'file_2', 'file_3'],
'service': 'ocr',
'args': {
'lang': 'deu'
}
}
job = background_scheduler.add_job(print, trigger='date', args=[job])
print(job)
return 'job'