Protect task diagnostics and stream incremental run output
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 38s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 47s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Successful in 1m24s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 38s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 43s
Build custom container images / build (map[base_image:php:8-fpm-alpine build_args:PHP_VERSION=8
context:php8-pgsql fingerprint_command:{ apk info -v | LC_ALL=C sort; find /usr/local/lib/php/extensions /usr/local/etc/php/conf.d -type f -exec sha256sum {} + | LC_ALL=C sort; }
name:ph… (push) Successful in 38s
Build custom container images / build (map[base_image:postgres:18 build_args:PG_VERSION=18
POSTGIS_VERSION=3
VCHORD_VERSION=0.5.3
context:postgres fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; find /usr/lib/postgresql -type f -exec sha256su… (push) Successful in 47s
Build custom container images / build (map[base_image:python:3 build_args:PYTHON_VERSION=3
context:python-tools fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:python-tools oci_labels:org.opencontainers.ima… (push) Successful in 1m24s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:linkki-tiedotus fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:linkki-tiedotus oci_labels:… (push) Successful in 38s
Build custom container images / build (map[base_image:python:3.12-slim build_args:PYTHON_VERSION=3.12-slim
context:timepoll fingerprint_command:{ dpkg-query -W -f='${binary:Package}=${Version}\n' | LC_ALL=C sort; pip freeze | LC_ALL=C sort; }
name:timepoll oci_labels:org.opencontai… (push) Successful in 43s
This commit is contained in:
1 parent
0aa67439fd
commit
55bbbe2fd7
8 files changed
+319
-51
No files matched your search
+33
-9
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import codecs
|
||||
import ipaddress
|
||||
import json
|
||||
from datetime import datetime
|
||||
@@ -137,11 +138,13 @@ def create_app(settings: Settings | None = None) -> Flask:
|
||||
if run is None:
|
||||
abort(404)
|
||||
execution_task = execution_replay_task(run)
|
||||
output, offset, _, _ = read_run_output(run)
|
||||
return render_template(
|
||||
"run.html",
|
||||
run=run,
|
||||
children=store.children(run.id),
|
||||
output=read_run_output(run),
|
||||
output=output,
|
||||
output_offset=offset,
|
||||
execution_task=execution_task,
|
||||
)
|
||||
|
||||
@@ -195,15 +198,36 @@ def create_app(settings: Settings | None = None) -> Flask:
|
||||
run = store.get(run_id)
|
||||
if run is None:
|
||||
abort(404)
|
||||
return {"output": read_run_output(run)}
|
||||
raw_offset = request.args.get("offset")
|
||||
if raw_offset is None:
|
||||
return {"output": read_run_output(run)[0]}
|
||||
if not raw_offset.isdecimal() or len(raw_offset) > 19 or int(raw_offset) > 2**63 - 1:
|
||||
abort(400)
|
||||
output, offset, reset, has_more = read_run_output(run, int(raw_offset), 1024 * 1024)
|
||||
return {
|
||||
"output": output, "offset": offset, "reset": reset, "has_more": has_more,
|
||||
"status": run.status,
|
||||
}
|
||||
|
||||
def read_run_output(run) -> str:
|
||||
def read_run_output(run, offset: int = 0, maximum_bytes: int | None = None) -> tuple[str, int, bool, bool]:
|
||||
if not run.log_path:
|
||||
return ""
|
||||
return "", 0, offset != 0, False
|
||||
try:
|
||||
return Path(run.log_path).read_text(encoding="utf-8", errors="replace")
|
||||
with Path(run.log_path).open("rb") as stream:
|
||||
stream.seek(0, 2)
|
||||
size = stream.tell()
|
||||
reset = offset > size
|
||||
if reset:
|
||||
offset = 0
|
||||
stream.seek(offset)
|
||||
data = stream.read() if maximum_bytes is None else stream.read(maximum_bytes)
|
||||
except FileNotFoundError:
|
||||
return ""
|
||||
return "", 0, offset != 0, False
|
||||
has_more = offset + len(data) < size
|
||||
decoder = codecs.getincrementaldecoder("utf-8")("replace")
|
||||
output = decoder.decode(data, final=run.status not in {"queued", "running"} and not has_more)
|
||||
pending, _ = decoder.getstate()
|
||||
return output, offset + len(data) - len(pending), reset, has_more
|
||||
|
||||
@app.get("/runs/<int:run_id>/artifacts")
|
||||
def run_artifacts(run_id: int):
|
||||
@@ -224,7 +248,7 @@ def create_app(settings: Settings | None = None) -> Flask:
|
||||
@app.get("/runs/<int:run_id>/artifacts/<filename>/view")
|
||||
def view_artifact(run_id: int, filename: str):
|
||||
run = store.get(run_id)
|
||||
if run is None or run.status != "succeeded" or not filename.casefold().endswith(".json"):
|
||||
if run is None or run.status in {"queued", "running"} or not filename.casefold().endswith(".json"):
|
||||
abort(404)
|
||||
artifact = manager.artifact_path(run.id, filename)
|
||||
if artifact is None:
|
||||
@@ -234,7 +258,7 @@ def create_app(settings: Settings | None = None) -> Flask:
|
||||
@app.get("/runs/<int:run_id>/artifacts/<filename>")
|
||||
def download_artifact(run_id: int, filename: str):
|
||||
run = store.get(run_id)
|
||||
if run is None or run.status != "succeeded":
|
||||
if run is None or run.status in {"queued", "running"} or (run.status != "succeeded" and not filename.casefold().endswith(".json")):
|
||||
abort(404)
|
||||
artifact = manager.artifact_path(run.id, filename)
|
||||
if artifact is None:
|
||||
@@ -250,11 +274,11 @@ def create_app(settings: Settings | None = None) -> Flask:
|
||||
def delete_after_transfer():
|
||||
try:
|
||||
yield from original_response
|
||||
manager.delete_artifact(run.id, artifact.name)
|
||||
finally:
|
||||
close = getattr(original_response, "close", None)
|
||||
if close is not None:
|
||||
close()
|
||||
manager.delete_artifact(run.id, artifact.name)
|
||||
|
||||
response.response = delete_after_transfer()
|
||||
response.direct_passthrough = False
|
||||
|
||||
Reference in new issue
Block a user