Commit 396f4491 authored by Joseph Weston's avatar Joseph Weston

Merge branch 'react' into dualstack

parents 3cd47350 ea59ba30
......@@ -13,7 +13,6 @@ import pandas
import cv2
import zbar
from flask import current_app as app
from pony import orm
from . import yaml_helper
......@@ -25,7 +24,7 @@ ExamMetadata = namedtuple('ExamMetadata',
['version', 'exam_name', 'qr_coords', 'widget_data'])
def process_pdf(pdf_id):
def process_pdf(pdf_id, data_directory):
"""Process a PDF, recording progress to a database
This *must* be called from a subprocess of the
......@@ -36,9 +35,9 @@ def process_pdf(pdf_id):
pdf_id : int
The ID in the database of the PDF to process
data_directory : str
The absolute path to the data directory on disk
data_directory = app.config['DATA_DIRECTORY']
report_error = functools.partial(write_pdf_status, pdf_id, 'error')
report_progress = functools.partial(write_pdf_status, pdf_id, 'processing')
report_success = functools.partial(write_pdf_status, pdf_id, 'success')
......@@ -88,7 +87,7 @@ def process_pdf(pdf_id):
# Process individual pages, ensuring we report the page numbers
# starting from 1.
failures = []
for i, (image, qr) in enumerate(1, zip(images, extracted_qrs)):
for i, (image, qr) in enumerate(zip(images, extracted_qrs), 1):
report_progress(f'Processing page {i} / {len(images)}')
if qr is None:
......@@ -76,7 +76,8 @@ class Pdfs(Resource):
# TODO: save these into a process-local datastructure, or save
# it into the DB as well so that we can cull 'processing' tasks
# that are actually dead.
Process(target=pdf_helper.process_pdf, args=(,)).start()
args = (, app.config['DATA_DIRECTORY'])
Process(target=pdf_helper.process_pdf, args=args).start()
return {
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment