From e7aad222959e581371ddabcbaa286f742d7eca92 Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 4 Jul 2025 11:45:15 -0400 Subject: [PATCH] Add backup and restore functionality to README documentation --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index fc9fb30..c6b2e57 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,8 @@ Configuration is set in `appsettings.json` or via environment variables. The mai - **ExpirationSeconds**: How long (in seconds) before an access ticket expires (default: 43200). - **RollingExpiration**: If true, the expiration timer resets on activity (default: true). - **CleanupIntervalSeconds**: How often (in seconds) the background cleanup runs to remove expired/inactive users (default: 60). +- **BackupFilePath**: The file path where the access queue state will be periodically saved (no default; optional). +- **BackupIntervalSeconds**: How often (in seconds) the state is backed up to disk (no default; optional). Example `appsettings.json`: ```json @@ -97,6 +99,28 @@ Example `appsettings.json`: } ``` +## State Persistence and Backup + +AccessQueueService automatically saves its in-memory state (active users and queue) to disk at regular intervals and restores it on startup. This helps prevent data loss in case of unexpected shutdowns or restarts. + +- **Backup Location:** The backup file path is set via the `AccessQueue:BackupFilePath` configuration variable. If this is not set, no backup will be performed. +- **Backup Interval:** The frequency of backups is controlled by `AccessQueue:BackupIntervalSeconds` (in seconds). If this is not set or is zero, backups are disabled. +- **Startup Restore:** On startup, if a backup file exists at the specified path, the service will attempt to restore the previous state from this file. If the file is missing or corrupted, the service starts with an empty queue and access list. +- **Failure Handling:** Any errors during backup or restore are logged, but do not prevent the service from running. +- **Backup Format:** The backup is saved as a JSON file containing the current state of the access queue and active users. + +Example configuration: +```json +{ + "AccessQueue": { + "BackupFilePath": "Logs/backup.json", + "BackupIntervalSeconds": 60 + } +} +``` + +> **Note:** Ensure the backup file path is writable by the service. Regular backups help prevent data loss in case of unexpected shutdowns. + ## AccessResponse Object The `AccessResponse` object returned by the API contains the following properties: