Add create corpus form to dashboard.

This commit is contained in:
Patrick Jentsch
2019-08-01 11:47:14 +02:00
parent a5b7ccaeb7
commit 716ebdfa7c
3 changed files with 71 additions and 53 deletions

View File

@ -18,32 +18,29 @@ def ocr():
id = hashlib.md5(
(current_user.username + '_' + datetime.now().isoformat()).encode()
).hexdigest()
'''
' TODO: Implement a Job class. For now a dictionary representation
' is enough.
'''
job = {'creator': current_user.id,
'id': id,
'requested_cpus': 2,
'requested_memory': 2048,
'service': 'ocr',
'service_args': {'lang': ocr_job_form.language.data,
'version': 'latest'
},
'status': 'queued'
}
dir = os.path.join(app.config['OPAQUE_FILES'], 'jobs', id)
try:
os.mkdir(dir)
except FileExistsError:
# Possible MD5 hash collision occurred.
flash('Internal error occurred, please try again!')
os.makedirs(dir)
except OSError:
flash('OSError!')
else:
file = ocr_job_form.file.data
file.save(os.path.join(dir, file.filename))
'''
' TODO: Implement a Job class. For now a dictionary representation
' is enough.
'''
job = {'worker': None,
'creator': current_user.id,
'id': id,
'requested_cpus': 2,
'requested_memory': 2048,
'service': 'ocr',
'service_args': {'lang': ocr_job_form.language.data,
'version': 'latest'
},
'status': 'queued'
}
'''
' TODO: Let the scheduler run this job in the background.
'
@ -52,6 +49,7 @@ def ocr():
'''
thread = Thread(target=swarm.run, args=(job,))
thread.start()
flash('Job created!')
return redirect(url_for('services.ocr'))
return render_template(