From d4a11a113e84caf7a7faf78cc79144afca36349a Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Thu, 15 May 2025 10:02:34 +0300 Subject: Add sync_after_write option to ctor --- femtoqueue.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/femtoqueue.py b/femtoqueue.py index 55211c2..059ca79 100644 --- a/femtoqueue.py +++ b/femtoqueue.py @@ -1,4 +1,4 @@ -from os import makedirs, path, listdir, rename, urandom +from os import makedirs, path, listdir, rename, urandom, fsync from dataclasses import dataclass import time from typing import Generator @@ -20,6 +20,7 @@ class FemtoQueue: data_dir: str, node_id: str, timeout_stale_ms: int = 30_000, + sync_after_write: bool = True, ): assert node_id not in self.RESERVED_NAMES self.node_id = node_id @@ -28,6 +29,8 @@ class FemtoQueue: self.timeout_stale_ms = timeout_stale_ms self.latest_stale_check_ts: float | None = None + self.sync_after_write = sync_after_write + self.todo_cache: Generator[str, None, None] | None = None self.data_dir = data_dir @@ -56,6 +59,8 @@ class FemtoQueue: with open(creating_path, "wb") as f: f.write(data) + if self.sync_after_write: + fsync(f) rename(creating_path, pending_path) -- cgit v1.3