From e83ecb5bfc800a0ad07a1ff56f61d08cc6aeb243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1igo=20Etxaniz?= Date: Fri, 2 Oct 2026 19:48:16 +0200 Subject: [PATCH] Initial content, migrated from the aml gateway rpi7-am-1 --- README.md | 9 ++++++++- bar_closer.py | 27 +++++++++++++++++++++++++++ schedule.yaml | 11 +++++++++++ signals.yml | 0 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 bar_closer.py create mode 100644 schedule.yaml create mode 100644 signals.yml diff --git a/README.md b/README.md index 0be8750..75015e5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ # bar-closer -Nightly close of oven_bar rows left without an exit \ No newline at end of file +Runs once a day at 04:00 and exits. Closes every `oven_bar` row that was opened but never +got an exit, setting `exited_time` to its `entered_time`, so a missed exit detection does not +leave a bar open forever and shift `bar-tracker`'s oldest-open matching. + +Reads no signals, which is why `signals.yml` is empty. Needs the db-controller reachable from +the job's sidecar. A query returns at most 100 rows, so more than 100 orphans take more than one +night to clear. Runs in `docker.izazpi.cloud/aml/aml-python`; the version is in +`schedule.yaml`. diff --git a/bar_closer.py b/bar_closer.py new file mode 100644 index 0000000..c2b2890 --- /dev/null +++ b/bar_closer.py @@ -0,0 +1,27 @@ +from i7lib.dbutils import Database +from i7lib.timeutils import to_datetime + + +def main(): + db = Database() + rows = db.query( + "oven_bar", + filters=[ + {"column": "exited_time", "op": "eq", "value": 0}, + {"column": "deleted", "op": "eq", "value": 0}, + ], + ) + if not rows: + print("no orphan bars to close") + return + + for row in rows: + db.update("oven_bar", row["id"], {"exited_time": row["entered_time"]}) + dt = to_datetime(row["entered_time"]).strftime("%Y-%m-%d %H:%M:%S") + print(f"closed orphan bar id={row['id']}, entered_time={dt}") + + print(f"closed {len(rows)} orphan bar(s)") + + +if __name__ == "__main__": + main() diff --git a/schedule.yaml b/schedule.yaml new file mode 100644 index 0000000..a90cc97 --- /dev/null +++ b/schedule.yaml @@ -0,0 +1,11 @@ +name: bar-closer +active: true +schedule: "0 4 * * *" +action: run +runOnStartup: false +imageName: docker.izazpi.cloud/aml/aml-python:0.1.0 +command: ["python", "/app/bar_closer.py"] +maxCpuCores: 0.5 +maxMemoryMb: 128 +autoremove: false +logOption: 1 diff --git a/signals.yml b/signals.yml new file mode 100644 index 0000000..e69de29