Add rest call to get job logs

This commit is contained in:
Brett Williams
2022-12-07 14:39:50 -08:00
parent 89b7cb38f7
commit cc394932a1
3 changed files with 37 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ from datetime import datetime
from zipfile import ZipFile
import requests
from flask import Flask, request, render_template, send_file, after_this_request
from flask import Flask, request, render_template, send_file, after_this_request, Response
from werkzeug.utils import secure_filename
from lib.render_job import RenderJob
@@ -44,6 +44,20 @@ def get_job_status(job_id):
return f'Cannot find job with ID {job_id}', 400
@server.get('/api/job/<job_id>/logs')
def get_job_logs(job_id):
found_job = RenderQueue.job_with_id(job_id)
if found_job:
log_path = found_job.worker.log_path
log_data = None
if log_path and os.path.exists(log_path):
with open(log_path) as file:
log_data = file.read()
return Response(log_data, mimetype='text/plain')
else:
return f'Cannot find job with ID {job_id}', 400
@server.get('/api/file_list/<job_id>')
def get_file_list(job_id):
found_job = RenderQueue.job_with_id(job_id)