diff --git a/requirements.txt b/requirements.txt index e6acba7..91045df 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ pypandoc flask gunicorn +celery[redis] diff --git a/server.py b/server.py index b12408d..24bec3c 100644 --- a/server.py +++ b/server.py @@ -3,11 +3,22 @@ import uuid import tempfile import os from flask import Flask, abort, request, Response, send_file +from celery import Celery import pypandoc app = Flask(__name__) app.logger.setLevel(logging.INFO) +# Celery setup and init +celery = Celery(app.import_name) +celery.conf.broker_url = 'redis://redis:6379/0' +celery.conf.worker_concurrency = 2 +@celery.on_after_configure.connect +def setup_periodic_tasks(sender, **kwargs): + sender.add_periodic_task(10.0, clean_up.s(), name="Cleanup") + app.logger.info('Cleanup periodic task setup') + + @app.route('/') def index(): return 'Hello' @@ -43,3 +54,8 @@ def convert(): if len(results) == 1: return send_file(results[0]['output']) return Response(str(results)) + + +@celery.task() +def clean_up(): + pass