Skip to content

Commit

Permalink
restore querylog exist grace period
Browse files Browse the repository at this point in the history
  • Loading branch information
sholdee committed Jun 27, 2024
1 parent 492122e commit 5681da3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions adguard_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,25 @@ def __init__(self, log_file_path, metrics_collector):
self.is_initialized = False
self.start_time = time.time()
self.last_inode = None
self.wait_for_log_file()
self.initial_load()

def get_inode(self):
return os.stat(self.log_file_path).st_ino if os.path.exists(self.log_file_path) else None

def wait_for_log_file(self):
max_wait_time = 120 # Maximum wait time in seconds
wait_interval = 5 # Interval between checks in seconds
start_time = time.time()
while not os.path.exists(self.log_file_path):
elapsed_time = time.time() - start_time
if elapsed_time >= max_wait_time:
logger.error(f"Log file did not appear within {max_wait_time} seconds.")
sys.exit(1)
logger.info(f"Waiting for log file to appear... ({int(elapsed_time)} seconds elapsed)")
time.sleep(wait_interval)
logger.info(f"Log file found: {self.log_file_path}")

def initial_load(self):
logger.info(f"Performing initial load of log file: {self.log_file_path}")
self.last_inode = self.get_inode()
Expand Down

0 comments on commit 5681da3

Please sign in to comment.