[projects/buildlogs] Update to avg calculation. --backfill won't use lock anymore (preventing adding new logs in locked t
arekm
arekm at pld-linux.org
Mon Apr 20 23:41:03 CEST 2026
commit e6c7f6b81b9a561eec07a562deeecfe1e0701c1f
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Mon Apr 20 23:40:02 2026 +0200
Update to avg calculation. --backfill won't use lock anymore (preventing adding new logs in locked time).
addlog.py | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
---
diff --git a/addlog.py b/addlog.py
index bfd5954..0075176 100755
--- a/addlog.py
+++ b/addlog.py
@@ -704,11 +704,12 @@ PROGRESS_EVERY = 1000
def _log_progress(log, phase, i, total, t0, last):
now = time.monotonic()
- rate = (i - last["i"]) / max(now - last["t"], 1e-6)
- eta = (total - i) / max(rate, 1e-6)
+ inst_rate = (i - last["i"]) / max(now - last["t"], 1e-6)
elapsed = now - t0
- log.info("backfill %s: %d/%d %.0f/s elapsed=%.1fs eta=%.1fmin",
- phase, i, total, rate, elapsed, eta / 60)
+ avg_rate = i / max(elapsed, 1e-6)
+ eta = (total - i) / max(avg_rate, 1e-6)
+ log.info("backfill %s: %d/%d %.0f/s (avg %.0f/s) elapsed=%.1fs eta=%.1fmin",
+ phase, i, total, inst_rate, avg_rate, elapsed, eta / 60)
last["t"] = now
last["i"] = i
@@ -820,16 +821,10 @@ def main(argv: list[str] | None = None) -> int:
os.umask(0o022)
args = build_parser().parse_args(argv)
cfg = load_config(args.config)
-
- lock_fd = acquire_lock(cfg.lock)
- if lock_fd is None:
- # Another instance holds the lock. Silent exit as specified.
- return 0
+ setup_logging(cfg.log, quiet=args.quiet, debug=args.debug)
+ install_signal_handlers()
try:
- setup_logging(cfg.log, quiet=args.quiet, debug=args.debug)
- install_signal_handlers()
- log = logging.getLogger("addlog")
conn = connect_db(cfg.database)
ensure_schema(conn)
if args.cleanup:
@@ -838,14 +833,20 @@ def main(argv: list[str] | None = None) -> int:
if args.backfill:
run_backfill(conn, cfg)
return 0
- full_scan(conn, cfg.root, workers=cfg.workers)
- run_watcher(conn, cfg)
- return 0
+ # Watcher is the only mode that needs single-instance protection —
+ # cron respawns it every minute for crash-restart.
+ lock_fd = acquire_lock(cfg.lock)
+ if lock_fd is None:
+ return 0 # another watcher already running, silent exit
+ try:
+ full_scan(conn, cfg.root, workers=cfg.workers)
+ run_watcher(conn, cfg)
+ return 0
+ finally:
+ release_lock(lock_fd)
except Exception:
logging.getLogger("addlog").exception("unhandled error")
return 1
- finally:
- release_lock(lock_fd)
if __name__ == "__main__":
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/buildlogs.git/commitdiff/e6c7f6b81b9a561eec07a562deeecfe1e0701c1f
More information about the pld-cvs-commit
mailing list