From b31a7528a834c3bb733f006cf34966e1dd40e092 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Fri, 30 May 2025 19:18:19 -0400 Subject: [PATCH] denis/configure: inform user when dumping dirty When the assignment database is altered, the due date waiters must be restarted in order for the new due dates to be operative using: $ denis/configure.sh reload Currently there is no way to know that one has forgotten to run this command. Add a warning message to the output of: $ denis/configure.sh dump to indicate when one has altered the database but not yet operationalized their intentions. Fixes #257 Signed-off-by: Joel Savitz --- denis/config.py | 1 + denis/configure.py | 9 +++++++++ denis/db.py | 3 ++- denis/start.py | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 denis/config.py diff --git a/denis/config.py b/denis/config.py new file mode 100644 index 00000000..a48af428 --- /dev/null +++ b/denis/config.py @@ -0,0 +1 @@ +RELOAD_FILE = '/tmp/denis_reload_file' diff --git a/denis/configure.py b/denis/configure.py index 7e5962c0..5ba46c49 100755 --- a/denis/configure.py +++ b/denis/configure.py @@ -3,8 +3,10 @@ from datetime import datetime from argparse import ArgumentParser as ap import sys +import os import db +import config # FIXME: if you are reading this in the year 9999... far_future = 253401417420 @@ -133,6 +135,11 @@ def timestamp_to_formatted(timestamp): dt = datetime.fromtimestamp(timestamp).astimezone() return dt.isoformat() if fmt_iso else dt.strftime('%a %b %d %Y %T %Z (%z)') + reload_mtime = os.path.getmtime(config.RELOAD_FILE) + db_mtime = os.path.getmtime(db.DB_PATH) + if (db_mtime > reload_mtime): + print('WARNING: Denis database is dirty, reload to update waiters') + print(' --- Assignments ---') for asn in db.Assignment.select(): print(f'''{asn.name}: @@ -146,6 +153,8 @@ def reload(): import signal try: os.kill(1, signal.SIGUSR1) + # update mtime/utime with last reload + os.utime(config.RELOAD_FILE) except OSError as e: errx(f'kill: {e}') diff --git a/denis/db.py b/denis/db.py index 7dcf00ac..fc9117da 100755 --- a/denis/db.py +++ b/denis/db.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 import peewee -DB = peewee.SqliteDatabase("/var/lib/denis/assignments.db") +DB_PATH = '/var/lib/denis/assignments.db' +DB = peewee.SqliteDatabase(DB_PATH) class BaseModel(peewee.Model): diff --git a/denis/start.py b/denis/start.py index e87a0da4..7d50854e 100755 --- a/denis/start.py +++ b/denis/start.py @@ -6,6 +6,7 @@ import sys import db +import config from configure import far_future @@ -62,6 +63,9 @@ def signal_handler(*_): signal.signal(signal.SIGUSR1, signal_handler) signal.signal(signal.SIGRTMIN, signal_handler) + # create reload file + open(config.RELOAD_FILE, 'w').close() + again = True while again: procs = []