From c7eedaa2ac2b550d1726b4b004ed27b4c29e7ea9 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 5 Sep 2025 14:56:37 -0400 Subject: Implement Graceful Shutdown for Worker Process This commit adds robust shutdown handling for the PodcastItLater worker process. Key improvements include: - Introduce ShutdownHandler to manage graceful signal handling - Add checkpoints in job processing to support interruption - Reset stale jobs stuck in processing state on startup - Modify systemd service configuration for better process management - Implement interruptible sleep in main loop - Ensure current job can complete or be reset during shutdown --- Biz/PodcastItLater/Worker.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Biz/PodcastItLater/Worker.nix') diff --git a/Biz/PodcastItLater/Worker.nix b/Biz/PodcastItLater/Worker.nix index eafc95a..974a3ba 100644 --- a/Biz/PodcastItLater/Worker.nix +++ b/Biz/PodcastItLater/Worker.nix @@ -48,10 +48,15 @@ in { "DATA_DIR=${cfg.dataDir}" ]; EnvironmentFile = "/run/podcastitlater/worker-env"; - KillSignal = "INT"; + KillSignal = "TERM"; + KillMode = "mixed"; Type = "simple"; Restart = "always"; RestartSec = "10"; + # Give the worker time to finish current job + TimeoutStopSec = "300"; # 5 minutes + # Send SIGTERM first, then SIGKILL after timeout + SendSIGKILL = "yes"; }; }; }; -- cgit v1.2.3