From 9bb8f359b102b02cf1e9efb973b26b118d5af64f Mon Sep 17 00:00:00 2001 From: Luis Perez Date: Fri, 10 Nov 2023 07:03:48 -0800 Subject: [PATCH] Stop backing up Tron EventBus events In the last N years, we've never had to do anything with the historical files - since they're just eating up disk space, let's just go to using a single file --- tron/eventbus.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/tron/eventbus.py b/tron/eventbus.py index 5f10a22a5..cf0a078ba 100644 --- a/tron/eventbus.py +++ b/tron/eventbus.py @@ -142,32 +142,25 @@ def sync_load_log(self): duration = time.time() - started log.info(f"log read from disk, took {duration:.4}s") - def sync_save_log(self, reason): + def sync_save_log(self, reason: str) -> None: started = time.time() - new_file = os.path.join(self.log_dir, f"{int(started)}.pickle") - try: - with open(new_file, "xb") as f: - pickle.dump(self.event_log, f) - except FileExistsError: - log.exception( - f"unable to dump the log, file {new_file} already exists, " - f"too many updates/sec? current: {self.log_updates}, " - f"threshold: {self.log_save_updates}", - ) - return False + pickle_file = os.path.join(self.log_dir, f"events.pickle") + with open(pickle_file, "wb") as f: + pickle.dump(self.event_log, f) + # XXX: cleanup symlink shenanigans once we're running with a + # XXX: single pickle file # atomically replace `current` symlink tmplink = os.path.join(self.log_dir, "tmp") try: os.remove(tmplink) except FileNotFoundError: pass - os.symlink(new_file, tmplink) + os.symlink(pickle_file, tmplink) os.replace(tmplink, self.log_current) duration = time.time() - started log.info(f"log dumped to disk because {reason}, took {duration:.4}s") - return True def sync_loop(self): if not self.enabled: @@ -192,7 +185,8 @@ def sync_process(self): elif self.log_updates > self.log_save_updates: save_reason = f"{self.log_save_updates} updates" - if save_reason and self.sync_save_log(save_reason): + if save_reason: + self.sync_save_log(save_reason) self.log_last_save = time.time() self.log_updates = 0