mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-26 03:14:19 +00:00
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from flask import render_template
|
|
from . import scheduler
|
|
from flask_login import current_user, login_required
|
|
from .. import background_scheduler
|
|
import json
|
|
import subprocess
|
|
|
|
|
|
@scheduler.route('/')
|
|
@login_required
|
|
def scheduler():
|
|
job = {
|
|
'creator': current_user.id,
|
|
'files': ['file_1', 'file_2', 'file_3'],
|
|
'service': 'ocr',
|
|
'service_args': {
|
|
'lang': 'deu'
|
|
},
|
|
'status': 'queued'
|
|
}
|
|
job = background_scheduler.add_job(process_job, trigger='date', args=[job])
|
|
print('### New job added for scheduling ###')
|
|
print(job)
|
|
return render_template('scheduler/index.html.j2', title='Scheduler')
|
|
|
|
|
|
def process_job(job):
|
|
input_dir = '/home/pjentsch/ocr/input'
|
|
output_dir = '/home/pjentsch/ocr/output'
|
|
|
|
job['status'] = 'running'
|
|
print('### Job status changed ###')
|
|
print(job)
|
|
|
|
subprocess.run([job['service'], '-i', input_dir, '-l', job['service_args']['lang'], '-o', output_dir, '--keep-intermediates'])
|
|
|
|
job['status'] = 'finished'
|
|
print('### Job status changed ###')
|
|
print(job)
|