from flask import redirect, render_template, url_for from . import services from flask_login import current_user, login_required from .forms import OCRJobForm from ..import swarm from threading import Thread @services.route('/ocr', methods=['GET', 'POST']) @login_required def ocr(): ocr_job_form = OCRJobForm() if ocr_job_form.validate_on_submit(): ''' ' TODO: Implement a Job class. For now a dictionary representation is ' enough. ''' job = {'worker': None, 'creator': current_user.id, 'id': '5fd40cb0cadef3ab5676c4968fc3d748', 'requested_cpus': 2, 'requested_memory': 2048, 'service': 'ocr', 'service_args': {'lang': 'eng', 'version': 'latest' }, 'status': 'queued' } ''' ' TODO: Let the scheduler run this job in the background. ' ' NOTE: Using self created threads is just for testing purpose as there ' is no scheduler available. ''' thread = Thread(target=swarm.run, args=(job,)) thread.start() return redirect(url_for('services.ocr')) return render_template( 'services/ocr.html.j2', title='Optical Character Recognition', ocr_job_form=ocr_job_form )