diff --git a/app/__init__.py b/app/__init__.py index 7080fdbc..f530b4d5 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,3 +1,4 @@ +from apscheduler.schedulers.background import BackgroundScheduler from config import config from flask import Flask from flask_login import LoginManager @@ -6,11 +7,14 @@ from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() -mail = Mail() login_manager = LoginManager() login_manager.login_view = 'auth.login' +mail = Mail() + +background_scheduler = BackgroundScheduler() + def create_app(config_name): app = Flask(__name__) @@ -27,4 +31,9 @@ def create_app(config_name): from .main import main as 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 diff --git a/app/scheduler/__init__.py b/app/scheduler/__init__.py new file mode 100644 index 00000000..447f8f5e --- /dev/null +++ b/app/scheduler/__init__.py @@ -0,0 +1,5 @@ +from flask import Blueprint + +scheduler = Blueprint('scheduler', __name__) + +from . import views diff --git a/app/scheduler/forms.py b/app/scheduler/forms.py new file mode 100644 index 00000000..e69de29b diff --git a/app/scheduler/views.py b/app/scheduler/views.py new file mode 100644 index 00000000..6ec0f011 --- /dev/null +++ b/app/scheduler/views.py @@ -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 scheduler(): + 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 render_template('scheduler/index.html.j2', title='Scheduler') diff --git a/app/templates/base.html.j2 b/app/templates/base.html.j2 index ab0260e4..469eb819 100644 --- a/app/templates/base.html.j2 +++ b/app/templates/base.html.j2 @@ -41,25 +41,21 @@
  • - - - - {% if current_user.is_authenticated %} - {{ current_user.username }} - {% else %} - Unknown - {% endif %} - - - - - + + + {% if current_user.is_authenticated %} + {{ current_user.username }} + {% else %} + Unknown + {% endif %} + +
  • opacityOpaque
  • diff --git a/app/templates/scheduler/index.html.j2 b/app/templates/scheduler/index.html.j2 new file mode 100644 index 00000000..8461d298 --- /dev/null +++ b/app/templates/scheduler/index.html.j2 @@ -0,0 +1,7 @@ +{% extends "base.html.j2" %} + +{% block page_content %} +
    + +
    +{% endblock %} diff --git a/requirements.txt b/requirements.txt index 46875f4b..18b0f129 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +APScheduler==3.6.0 Flask==1.0.3 Flask-Login==0.4.1 Flask-Mail==0.9.1