Adding celery to run a cleanup job periodicly
This commit is contained in:
parent
14657f85a5
commit
54872357fa
|
@ -1,3 +1,4 @@
|
|||
pypandoc
|
||||
flask
|
||||
gunicorn
|
||||
celery[redis]
|
||||
|
|
16
server.py
16
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
|
||||
|
|
Loading…
Reference in New Issue