Adding celery to run a cleanup job periodicly

This commit is contained in:
Alex Wright 2018-11-05 20:33:17 +01:00
parent 14657f85a5
commit 54872357fa
2 changed files with 17 additions and 0 deletions

View File

@ -1,3 +1,4 @@
pypandoc
flask
gunicorn
celery[redis]

View File

@ -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