Switched to an eta= based async task
This commit is contained in:
parent
1e2c147f7f
commit
536ec3871c
12
server.py
12
server.py
|
@ -2,8 +2,9 @@ import logging
|
|||
import uuid
|
||||
import tempfile
|
||||
import os
|
||||
from flask import Flask, abort, request, Response, send_file
|
||||
from celery import Celery
|
||||
from datetime import datetime, timedelta
|
||||
from flask import Flask, abort, request, Response, send_file
|
||||
import pypandoc
|
||||
|
||||
app = Flask(__name__)
|
||||
|
@ -15,7 +16,6 @@ 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')
|
||||
|
||||
|
||||
|
@ -33,6 +33,9 @@ def convert():
|
|||
|
||||
job_name = uuid.uuid4().hex
|
||||
job_dir = tempfile.mkdtemp(suffix='-' + job_name)
|
||||
later = datetime.utcnow() + timedelta(hours=1)
|
||||
clean_up.apply_async((job_dir, ), eta=later)
|
||||
|
||||
input_file = request.files['input']
|
||||
input_base, input_ext = input_file.filename.rsplit('.')
|
||||
input_path = os.path.join(job_dir, 'input.' + input_ext)
|
||||
|
@ -43,7 +46,7 @@ def convert():
|
|||
for output in outputs:
|
||||
output_filename = '{0}.{1}'.format(input_base, output)
|
||||
output_path = os.path.join(job_dir, output_filename)
|
||||
logger.info('Converting {0} to {1}'.format(input_path, output_path))
|
||||
app.logger.info('Converting {0} to {1}'.format(input_path, output_path))
|
||||
pypandoc.convert(input_path, output, outputfile=output_path)
|
||||
results.append({
|
||||
'input': input_path,
|
||||
|
@ -56,5 +59,6 @@ def convert():
|
|||
|
||||
|
||||
@celery.task()
|
||||
def clean_up():
|
||||
def clean_up(path):
|
||||
app.logger.info('Deleting work dir %s', path)
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue