Skip to content

Commit a68d2ac

Browse files
fix plugins, new log endpoints
1 parent b711b05 commit a68d2ac

File tree

8 files changed

+63
-234
lines changed

8 files changed

+63
-234
lines changed

asset-manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"files": {
33
"main.css": "/static/css/main.a3dbeddd.css",
4-
"main.js": "/static/js/main.fefe4003.js",
4+
"main.js": "/static/js/main.6a00b6d2.js",
55
"static/media/roboto-all-500-normal.woff": "/static/media/roboto-all-500-normal.0ab669b7a0d19b178f57.woff",
66
"static/media/roboto-all-700-normal.woff": "/static/media/roboto-all-700-normal.a457fde362a540fcadff.woff",
77
"static/media/roboto-all-400-normal.woff": "/static/media/roboto-all-400-normal.c5d001fa922fa66a147f.woff",
@@ -36,10 +36,10 @@
3636
"static/media/roboto-greek-ext-700-normal.woff2": "/static/media/roboto-greek-ext-700-normal.bd9854c751441ccc1a70.woff2",
3737
"index.html": "/index.html",
3838
"main.a3dbeddd.css.map": "/static/css/main.a3dbeddd.css.map",
39-
"main.fefe4003.js.map": "/static/js/main.fefe4003.js.map"
39+
"main.6a00b6d2.js.map": "/static/js/main.6a00b6d2.js.map"
4040
},
4141
"entrypoints": [
4242
"static/css/main.a3dbeddd.css",
43-
"static/js/main.fefe4003.js"
43+
"static/js/main.6a00b6d2.js"
4444
]
4545
}

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Pioreactor"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.fefe4003.js"></script><link href="/static/css/main.a3dbeddd.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
1+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Pioreactor"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><script defer="defer" src="/static/js/main.6a00b6d2.js"></script><link href="/static/css/main.a3dbeddd.css" rel="stylesheet"></head><body><div id="root"></div></body></html>

pioreactorui/api.py

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ def get_recent_logs(experiment: str) -> ResponseReturnValue:
351351

352352
try:
353353
recent_logs = query_app_db(
354-
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task
354+
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task, l.experiment
355355
FROM logs AS l
356356
WHERE (l.experiment=? OR l.experiment=?)
357357
AND ({get_level_string(min_level)})
358-
AND l.timestamp >= MAX( STRFTIME('%Y-%m-%dT%H:%M:%f000Z', 'NOW', '-24 hours')), (SELECT created_at FROM experiments where experiment=?) )
358+
AND l.timestamp >= MAX( STRFTIME('%Y-%m-%dT%H:%M:%f000Z', 'NOW', '-24 hours'), (SELECT created_at FROM experiments where experiment=?) )
359359
ORDER BY l.timestamp DESC LIMIT 50;""",
360360
(experiment, UNIVERSAL_EXPERIMENT, experiment),
361361
)
@@ -368,14 +368,14 @@ def get_recent_logs(experiment: str) -> ResponseReturnValue:
368368

369369

370370
@api.route("/experiments/<experiment>/logs", methods=["GET"])
371-
def get_logs(experiment: str) -> ResponseReturnValue:
371+
def get_exp_logs(experiment: str) -> ResponseReturnValue:
372372
"""Shows event logs from all units, uses pagination."""
373373

374374
skip = int(request.args.get("skip", 0))
375375

376376
try:
377377
recent_logs = query_app_db(
378-
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task
378+
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task, l.experiment
379379
FROM logs AS l
380380
JOIN experiment_worker_assignments_history h
381381
on h.pioreactor_unit = l.pioreactor_unit
@@ -386,6 +386,26 @@ def get_logs(experiment: str) -> ResponseReturnValue:
386386
(experiment, UNIVERSAL_EXPERIMENT),
387387
)
388388

389+
except Exception as e:
390+
publish_to_error_log(str(e), "get_exp_logs")
391+
return Response(status=500)
392+
393+
return jsonify(recent_logs)
394+
395+
396+
@api.route("/logs", methods=["GET"])
397+
def get_logs() -> ResponseReturnValue:
398+
"""Shows event logs from all units, uses pagination."""
399+
400+
skip = int(request.args.get("skip", 0))
401+
402+
try:
403+
recent_logs = query_app_db(
404+
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task, l.experiment
405+
FROM logs AS l
406+
ORDER BY l.timestamp DESC LIMIT 50 OFFSET {skip};"""
407+
)
408+
389409
except Exception as e:
390410
publish_to_error_log(str(e), "get_logs")
391411
return Response(status=500)
@@ -420,7 +440,7 @@ def get_recent_logs_for_unit_and_experiment(
420440

421441
try:
422442
recent_logs = query_app_db(
423-
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task
443+
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task, l.experiment
424444
FROM logs AS l
425445
WHERE (l.experiment=? OR l.experiment=?)
426446
AND (l.pioreactor_unit=? or l.pioreactor_unit=?)
@@ -445,7 +465,7 @@ def get_logs_for_unit_and_experiment(pioreactor_unit: str, experiment: str) -> R
445465

446466
try:
447467
recent_logs = query_app_db(
448-
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task
468+
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task, l.experiment
449469
FROM logs AS l
450470
JOIN experiment_worker_assignments_history h
451471
on h.pioreactor_unit = l.pioreactor_unit
@@ -458,7 +478,29 @@ def get_logs_for_unit_and_experiment(pioreactor_unit: str, experiment: str) -> R
458478
)
459479

460480
except Exception as e:
461-
publish_to_error_log(str(e), "get_get_logs_for_unit_and_experimentlogs")
481+
publish_to_error_log(str(e), "get_for_unit_and_experiment")
482+
return Response(status=500)
483+
484+
return jsonify(recent_logs)
485+
486+
487+
@api.route("/units/<pioreactor_unit>/logs", methods=["GET"])
488+
def get_logs_for_unit(pioreactor_unit: str) -> ResponseReturnValue:
489+
"""Shows event logs from all units, uses pagination."""
490+
491+
skip = int(request.args.get("skip", 0))
492+
493+
try:
494+
recent_logs = query_app_db(
495+
f"""SELECT l.timestamp, level, l.pioreactor_unit, message, task, l.experiment
496+
FROM logs AS l
497+
WHERE (l.pioreactor_unit=? or l.pioreactor_unit=?)
498+
ORDER BY l.timestamp DESC LIMIT 50 OFFSET {skip};""",
499+
(pioreactor_unit, UNIVERSAL_IDENTIFIER),
500+
)
501+
502+
except Exception as e:
503+
publish_to_error_log(str(e), "get_logs_for_unit")
462504
return Response(status=500)
463505

464506
return jsonify(recent_logs)

pioreactorui/tasks.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ def pio(*args: str, env: dict[str, str] = {}) -> bool:
159159
return result.returncode == 0
160160

161161

162+
@huey.task()
163+
def pio_plugins_list(*args: str, env: dict[str, str] = {}) -> tuple[bool, str]:
164+
logger.info(f'Executing `{join(("pio",) + args)}`, {env=}')
165+
result = run(
166+
(PIO_EXECUTABLE,) + args, capture_output=True, text=True, env=dict(os.environ) | env
167+
)
168+
return result.returncode == 0, result.stdout.strip()
169+
170+
162171
@huey.task()
163172
@huey.lock_task("export-data-lock")
164173
def pio_run_export_experiment_data(*args: str, env: dict[str, str] = {}) -> bool:

pioreactorui/unit_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def update_job(job: str) -> ResponseReturnValue:
337337

338338
@unit_api.route("/plugins/installed", methods=["GET"])
339339
def get_installed_plugins() -> ResponseReturnValue:
340-
result = tasks.pio("plugins", "list", "--json")
340+
result = tasks.pio_plugins_list("plugins", "list", "--json")
341341
try:
342342
status, msg = result(blocking=True, timeout=120)
343343
except HueyException:

static/js/main.fefe4003.js

Lines changed: 0 additions & 103 deletions
This file was deleted.

static/js/main.fefe4003.js.LICENSE.txt

Lines changed: 0 additions & 118 deletions
This file was deleted.

static/js/main.fefe4003.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)