2019-07-10 11:41:48 +00:00
|
|
|
from flask import render_template
|
|
|
|
from . import scheduler
|
|
|
|
from flask_login import current_user, login_required
|
|
|
|
from .. import background_scheduler
|
|
|
|
import json
|
2019-07-11 07:40:12 +00:00
|
|
|
import subprocess
|
2019-07-10 11:41:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
@scheduler.route('/')
|
|
|
|
@login_required
|
2019-07-10 12:20:22 +00:00
|
|
|
def scheduler():
|
2019-07-10 11:41:48 +00:00
|
|
|
job = {
|
|
|
|
'creator': current_user.id,
|
|
|
|
'files': ['file_1', 'file_2', 'file_3'],
|
|
|
|
'service': 'ocr',
|
2019-07-10 12:37:31 +00:00
|
|
|
'service_args': {
|
2019-07-10 11:41:48 +00:00
|
|
|
'lang': 'deu'
|
2019-07-10 12:37:31 +00:00
|
|
|
},
|
|
|
|
'status': 'queued'
|
2019-07-10 11:41:48 +00:00
|
|
|
}
|
2019-07-11 07:40:12 +00:00
|
|
|
job = background_scheduler.add_job(process_job, trigger='date', args=[job])
|
|
|
|
print('### New job added for scheduling ###')
|
|
|
|
print(job)
|
2019-07-10 12:20:22 +00:00
|
|
|
return render_template('scheduler/index.html.j2', title='Scheduler')
|
2019-07-11 07:40:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def process_job(job):
|
2019-07-11 07:40:37 +00:00
|
|
|
<<<<<<< HEAD
|
2019-07-11 07:40:12 +00:00
|
|
|
input_dir = '/home/pjentsch/%s/input' % job['service']
|
|
|
|
output_dir = '/home/pjentsch/%s/output' % job['service']
|
2019-07-11 07:40:37 +00:00
|
|
|
=======
|
2019-07-11 07:35:55 +00:00
|
|
|
input_dir = '/home/pjentsch/ocr/input'
|
|
|
|
output_dir = '/home/pjentsch/ocr/output'
|
2019-07-11 07:40:37 +00:00
|
|
|
>>>>>>> e6446834b4c4251154497a7104cd84d1188be981
|
2019-07-11 07:40:12 +00:00
|
|
|
|
|
|
|
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)
|