def run_get_artifact(proj, build_id, run, path): r = _get_run(proj, build_id, run) if r.complete: storage = Storage() if path.endswith('.html'): # we are probably trying to render a static site like a build of # ltd-docs. Return its content rather than a redirect so it will # render in the browser content = storage.get_artifact_content(r, path) return content, 200, {'Content-Type': 'text/html'} resp = storage.get_download_response(request, r, path) resp.headers['X-RUN-STATUS'] = r.status.name return resp if path != 'console.log': raise ApiError( 404, {'message': 'Run in progress, no artifacts available'}) if r.status == BuildStatus.QUEUED: msg = '# Waiting for worker with tag: ' + r.host_tag return (msg, 200, {'Content-Type': 'text/plain', 'X-RUN-STATUS': r.status.name}) try: fd = Storage().console_logfd(r, 'rb') offset = request.headers.get('X-OFFSET') if offset: fd.seek(int(offset), 0) resp = make_response(send_file(fd, mimetype='text/plain')) resp.headers['X-RUN-STATUS'] = r.status.name return resp except FileNotFoundError: # This is a race condition. The run completed while we were checking return Storage().get_download_response(request, r, path)
def run_get_artifact(proj, build_id, run, path): r = _get_run(proj, build_id, run) if r.complete: storage = Storage() if path.endswith(".html"): # we are probably trying to render a static site like a build of # ltd-docs. Return its content rather than a redirect so it will # render in the browser content = storage.get_artifact_content(r, path) return content, 200, {"Content-Type": "text/html"} resp = storage.get_download_response(request, r, path) resp.headers["X-RUN-STATUS"] = r.status.name return resp if path != "console.log": raise ApiError(404, {"message": "Run in progress, no artifacts available"}) if r.status == BuildStatus.QUEUED: msg = "# Waiting for worker with tag: " + r.host_tag return (msg, 200, { "Content-Type": "text/plain", "X-RUN-STATUS": r.status.name }) try: fd = Storage().console_logfd(r, "rb") offset = request.headers.get("X-OFFSET") if offset: offset = int(offset) end = fd.seek(0, 2) if offset >= end: return ( b"", 200, { "Content-Type": "text/html", "X-RUN-STATUS": r.status.name }, ) fd.seek(offset, 0) resp = make_response(send_file(fd, mimetype="text/plain")) resp.headers["X-RUN-STATUS"] = r.status.name return resp except FileNotFoundError: # This is a race condition. The run completed while we were checking return Storage().get_download_response(request, r, path)