diff --git a/deploy/unraid/chronos.xml b/deploy/unraid/chronos.xml index 8f79b701..f3ea9f0f 100644 --- a/deploy/unraid/chronos.xml +++ b/deploy/unraid/chronos.xml @@ -51,5 +51,5 @@ 99 100 - Europe/Rome + Europe/Rome diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 3822ffa8..cdc8bc49 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -85,17 +85,17 @@ Dependencies point one way: `Core` ← `Core.Windows`, `Data`, `Protocol` ← `S | `Ui/Controls` | `ChronosWindow` (chrome, language direction), `NavRail`, `JobBar`, `ToastHost`, `Field` (placeholder, icon, error), `Chip`, `AutoSlider`, `StatusGlyph`, `EmptyState`, `Icon`, `Bidi` (right-to-left rules), `Motion` (animations off for screenshots) | | `Ui/Interop` | DWM calls of the window chrome; `TrayIcon` (`Shell_NotifyIconW`: the Uploader's tray, the client's Windows notifications) | | `Ui/Visuals` | `DrawingElement` (hover readout, item keyboard and activation) and its charts (`BarChart`, `SeriesChart`, `StackedBar`, `HeatmapStrip`, `TimelineBands`), `Filmstrip`, `PreviewViewport`, `CurveEditor`, `SequenceCard`, `VirtualizingWrapPanel`, `SegmentedControl`, `SplitButton` | -| `Server/Api`, `Server/Events` | Endpoint groups (`XxxEndpoints.Map`), API errors, the WebSocket `EventHub` | +| `Server/Api`, `Server/Events` | Endpoint groups (`XxxEndpoints.Map`; `ScheduleEndpoints`: `/api/v1/schedules`), API errors, the WebSocket `EventHub` | | `Server/Security` | Accounts, password hashing, tokens, session cookies, login guard, access rules, audit log | -| `Server/Storage`, `Server/Jobs` | Archive and processing modules, uploads, render store; `JobEngineHost`, render node service, monitor and availability | -| `Server/Hosting`, `Server/Admin/web` | `ServerHost`, `ServerLogging` (console and file levels the logging filters read at every line, the file sink's limits, the engine's level; applied again when Settings › Logs is saved), certificates, discovery beacon, embedded static files, Windows service (start and stop failures in the Application event log); the admin panel (ES modules, one per page) | +| `Server/Storage`, `Server/Jobs` | Archive and processing modules, uploads (`UploadMaintenance`: recovery at start, and the sweep that is the `uploads` clean-up step), render store; `JobEngineHost`, `SchedulerHost` (the `Scheduler` on the engine, started after it) and `ServerScheduleHost` (time zone, archive refreshed from archive.json, system schedules), render node service, monitor and availability | +| `Server/Hosting`, `Server/Admin/web` | `ServerHost`, `ServerLogging` (console and file levels the logging filters read at every line, the file sink's limits, the engine's level; applied again when Settings › Logs is saved), certificates, discovery beacon, embedded static files, Windows service (start and stop failures in the Application event log); the admin panel (ES modules, one per page; `schedules.js` is the Jobs page's Scheduled tab) | ### 2.5 Hosts | Host | Composition root | What it runs | |---|---|---| | Chronos (desktop) | `App/Infrastructure/AppServices` | SQLite index in `%LOCALAPPDATA%\Chronos` (or `.\data` when portable, unless the copy is in a OneDrive folder); `ArchiveService` with WIC first, then managed decoders; `ProcessingService` with Media Foundation, then managed encoders; one `JobEngine` with the handlers of both; thumbnails; `ServerSession`; `SyncHost` while signed in (sync engine and agent, upload and download handlers, metered hold, editors of server sequences); the render node while opted in and signed in; update check and download (`About/UpdateCheck`, `About/UpdateDownload`, `About/UpdateFlow`: the setup, or the portable zip for a portable copy, verified against `SHA256SUMS`, resumable, cancellable, failing after 60 s without data); diagnostics bundle; daily index backups and the restore staged in Settings › Advanced (`DatabaseBackups`) | -| Chronos Server | `Server/Hosting/ServerHost.Build` | Options from `server.json` + `CHRONOS_*`; PostgreSQL (or SQLite on Windows); `ArchiveModule` then `ProcessingModule` register job handler providers; `JobEngineHost` (renders only managed formats and MP4 jobs no render node can take, BRIEF §14.7); `RenderNodeService`/`RenderNodeMonitor`; `UploadService`; `VolumeSpace` (free space of the archive, the space path and `/data`, file system and mount from `/proc/self/mountinfo`; tests replace it); `EventHub` (WebSocket); embedded admin panel; LAN discovery beacon; Windows service host; daily backups of an SQLite index (`DatabaseBackupService`) | +| Chronos Server | `Server/Hosting/ServerHost.Build` | Options from `server.json` + `CHRONOS_*`; PostgreSQL (or SQLite on Windows); `ArchiveModule` then `ProcessingModule` register job handler providers; `JobEngineHost` (renders only managed formats and MP4 jobs no render node can take, BRIEF §14.7); `RenderNodeService`/`RenderNodeMonitor`; `UploadService`; `VolumeSpace` (free space of the archive, the space path and `/data`, file system and mount from `/proc/self/mountinfo`; tests replace it); `EventHub` (WebSocket); embedded admin panel; LAN discovery beacon; Windows service host; `SchedulerHost` with the system schedules `archive-scan` (every 10 minutes, also once at start), `upload-cleanup` (every 30 minutes), `index-backup` (SQLite only, 03:00), `housekeeping` (job history, 04:00) and `audit-cleanup` (04:30), no other timer queues work | | Chronos Uploader | `Uploader/App.xaml.cs` | `ChronosClient`, persisted queue, watch folders; no database | | Chronos Setup | `Setup/Program` | TPK1 payload extraction, registry, shortcuts, file types named in setup's language, silent mode, uninstaller; only what starts a program its log or payload lists is changed: Windows services of those programs stopped once the programs have closed, started again (also after a failure) or deleted through the Service Control Manager (an elevated `/SERVICES … /NAMES` step when needed), sign-in entries of those programs moved to the program an upgrade renamed or removed, shared shortcuts handed to the product that keeps the program; the Server only for all users inside Program Files; "Remove my data" limited to the programs no other installed product uses | diff --git a/i18n/ar/Admin.ar.resx b/i18n/ar/Admin.ar.resx index 2c0ef1d3..aab4deaf 100644 --- a/i18n/ar/Admin.ar.resx +++ b/i18n/ar/Admin.ar.resx @@ -309,8 +309,6 @@ منفذ لوحة الإدارة وواجهة API عبر HTTP منفذ HTTPS منفذ واجهة API عبر TLS لتطبيقات Chronos - سجل المهام (أيام) - عدد أيام الاحتفاظ بالمهام المنتهية مستوى «{0}» في قائمة انتظار الأولوية: مهام المستوى الأعلى تعمل أولًا وتوقف مهام المستويات الأدنى مؤقتًا المهام اللغة @@ -332,7 +330,6 @@ ليس عبر الوكيل وضع TLS هو «وكيل عكسي»، لكن هذه الصفحة لم تصل عبر وكيل موثوق باستخدام HTTPS. افتحها عبر الوكيل، أو أضف عنوان الوكيل إلى CHRONOS_TRUSTED_PROXIES. يلزم إعادة التشغيل - تُطبَّق التغييرات المحفوظة على المنافذ أو TLS أو وحدات التنفيذ أو حجم الجزء أو سجل المهام بعد إعادة التشغيل الخادم اسم الخادم الاسم الذي يظهر لتطبيقات العميل وعلى الشبكة المحلية diff --git a/i18n/bg/Admin.bg.resx b/i18n/bg/Admin.bg.resx index a4a8c7a0..4412a2b1 100644 --- a/i18n/bg/Admin.bg.resx +++ b/i18n/bg/Admin.bg.resx @@ -283,8 +283,6 @@ Порт на администраторския панел и на API през HTTP HTTPS порт Порт на API през TLS за клиентите на Chronos - История на задачите (дни) - Брой дни, през които завършените задачи се пазят Ниво на „{0}“ в приоритетната опашка: задачите с по-високо ниво се изпълняват първи и поставят на пауза по-ниските Задачи Език @@ -306,7 +304,6 @@ Без прокси Режимът на TLS е „Обратен прокси сървър“, но тази страница не е дошла през доверен прокси сървър по HTTPS. Отворете я през вашия прокси сървър или добавете адреса му в CHRONOS_TRUSTED_PROXIES. Нужно е рестартиране - Записаните портове, TLS, обработчици, размер на част и история на задачите влизат в сила след рестартиране Сървър Име на сървъра Името, показвано на клиентите и в локалната мрежа diff --git a/i18n/cs/Admin.cs.resx b/i18n/cs/Admin.cs.resx index 37358035..c546b710 100644 --- a/i18n/cs/Admin.cs.resx +++ b/i18n/cs/Admin.cs.resx @@ -296,8 +296,6 @@ Port panelu správy a API přes HTTP Port HTTPS Port API přes TLS pro klienty Chronos - Historie úloh (dny) - Počet dní, po které se dokončené úlohy uchovávají Úroveň „{0}“ v prioritní frontě: vyšší úroveň běží dřív a pozastavuje nižší úrovně Úlohy Jazyk @@ -319,7 +317,6 @@ Mimo proxy Režim TLS je „Reverzní proxy“, ale tato stránka nepřišla přes důvěryhodnou proxy pomocí HTTPS. Otevřete ji přes svou proxy, nebo přidejte adresu proxy do CHRONOS_TRUSTED_PROXIES. Vyžaduje restart - Uložené porty, TLS, pracovní procesy, velikost bloku a historie úloh se projeví po restartu Server Název serveru Název zobrazovaný klientům a v místní síti diff --git a/i18n/da/Admin.da.resx b/i18n/da/Admin.da.resx index 8e9c92e9..121cd783 100644 --- a/i18n/da/Admin.da.resx +++ b/i18n/da/Admin.da.resx @@ -283,8 +283,6 @@ Port til administrationspanelet og API'et over HTTP HTTPS-port Port til API'et over TLS for Chronos-klienter - Jobhistorik (dage) - Antal dage, som færdige job gemmes Niveauet for »{0}« i prioritetskøen: et højere niveau kører først og sætter lavere niveauer på pause Job Sprog @@ -306,7 +304,6 @@ Ikke via proxy TLS-tilstanden er Omvendt proxy, men denne side kom ikke via en betroet proxy over HTTPS. Åbn den via din proxy, eller føj proxyens adresse til CHRONOS_TRUSTED_PROXIES. Genstart påkrævet - Ændringer af porte, TLS, processer, blokstørrelse eller jobhistorik træder i kraft efter en genstart Server Servernavn Navn, der vises for klienter og på LAN'et diff --git a/i18n/de/Admin.de.resx b/i18n/de/Admin.de.resx index 17bafbbf..9e215316 100644 --- a/i18n/de/Admin.de.resx +++ b/i18n/de/Admin.de.resx @@ -283,8 +283,6 @@ Port des Admin-Bereichs und der API über HTTP HTTPS-Port Port der API über TLS für Chronos-Clients - Auftragsverlauf (Tage) - Anzahl Tage, die abgeschlossene Aufträge aufbewahrt werden Stufe von „{0}“ in der Prioritätswarteschlange: Eine höhere Stufe läuft zuerst und hält niedrigere an Aufträge Sprache @@ -306,7 +304,6 @@ Ohne Proxy Der TLS-Modus ist „Reverse-Proxy“, aber diese Seite wurde nicht über einen vertrauenswürdigen Proxy per HTTPS aufgerufen. Öffnen Sie sie über Ihren Proxy, oder fügen Sie die Adresse des Proxys zu CHRONOS_TRUSTED_PROXIES hinzu. Neustart erforderlich - Gespeicherte Änderungen an Ports, TLS, Workern, Blockgröße oder Auftragsverlauf gelten erst nach einem Neustart Server Servername Name, der den Clients und im LAN angezeigt wird diff --git a/i18n/el/Admin.el.resx b/i18n/el/Admin.el.resx index 29b38638..15378d42 100644 --- a/i18n/el/Admin.el.resx +++ b/i18n/el/Admin.el.resx @@ -283,8 +283,6 @@ Θύρα του πίνακα διαχείρισης και του API μέσω HTTP Θύρα HTTPS Θύρα του API μέσω TLS για τα προγράμματα-πελάτες Chronos - Ιστορικό εργασιών (ημέρες) - Ημέρες διατήρησης των ολοκληρωμένων εργασιών Επίπεδο για «{0}» στην ουρά προτεραιότητας: ένα υψηλότερο επίπεδο εκτελείται πρώτο και θέτει σε παύση τα χαμηλότερα Εργασίες Γλώσσα @@ -306,7 +304,6 @@ Όχι μέσω proxy Η λειτουργία TLS είναι «Μέσω reverse proxy», αλλά αυτή η σελίδα δεν ήρθε μέσω αξιόπιστου proxy με HTTPS. Ανοίξτε την μέσω του proxy σας ή προσθέστε τη διεύθυνση του proxy στο CHRONOS_TRUSTED_PROXIES. Απαιτείται επανεκκίνηση - Οι αποθηκευμένες θύρες, το TLS, οι εκτελεστές, το μέγεθος τμήματος και το ιστορικό εργασιών εφαρμόζονται μετά από επανεκκίνηση Διακομιστής Όνομα διακομιστή Όνομα που εμφανίζεται στα προγράμματα-πελάτες και στο LAN diff --git a/i18n/en/Admin.resx b/i18n/en/Admin.resx index b202ef1f..1a172f32 100644 --- a/i18n/en/Admin.resx +++ b/i18n/en/Admin.resx @@ -15,6 +15,11 @@ failed sign-in as {0}long {0} changed their passwordlong {0} reset the password of {1}long + {0} created the schedule {1}long + {0} deleted the schedule {1}long + {0} reset the schedule {1}long + {0} ran the schedule {1}long + {0} changed the schedule {1}long {0} created {1}long {0} deleted {1}long {0} edited a sequence · {1}long @@ -183,10 +188,16 @@ Queue the job again from its last checkpoint {0} running {0} running + Scheduled + Queued by a schedule: show it on the Scheduled tab server Show all Show jobs in every state State + Queue + Jobs waiting, running and finished, and the render nodes + Scheduled + Jobs the server queues by itself on a schedule: see, create and change them Target Language of this panel Wrong user name or password.long @@ -203,6 +214,11 @@ Failed sign-in Password changed Password reset + Schedule created + Schedule deleted + Schedule reset + Schedule run + Schedule changed Sequence created Sequence deleted Sequence edited @@ -275,6 +291,147 @@ Editor Uploader Viewer + Action + Analysis + Analyse the sequences without a current analysis + Index backup + Copy the index into the backups folder and keep the newest copies + Clean-up + Remove old job history, audit entries and what uploads left behind + Duplicates report + List the duplicate photos in the job log; nothing is changed + Maintenance + Remove stale locks and temporary files and compact the archive's packs and index + Orphans report + List in the job log where the index and the disk disagree; nothing is changed + Proxies + Make the proxies sequences are missing, when the archive makes proxies + Archive scan + Index the photos added to or changed in the archive folder + Thumbnails + Make the thumbnails sequences are missing + What the schedule does when it runs + Integrity check + Read the originals and compare them with their hashes, the least recently checked first + Catch up + Run once at start when a run was missed while the server was off + {0} schedule + {0} schedules + Create + Create this schedule + Daily at {0} + Run on {0} + Day of month + Day of the month it runs on, 1 to 28 + Days + Delete + Delete this schedule; the jobs it queued stay in the history + Delete {0}? + Edit + Change when and how this schedule runs + Edit schedule + No schedules + Enabled + On, the schedule runs by itself; off, only Run now runs it + Enabled: {0} + Every day + Every {0} days + Every hour + Every {0} hours + Every minute + Every {0} minutes + A system schedule keeps its name and action + Every + Time between two runs: at least 5 minutes, at most 1440 minutes, 168 hours or 366 days + Daily + At an interval + Monthly + Weekly + Last result + Day {0} of each month at {1} + Name + A name to recognise the schedule by + Not run yet + New schedule + Create a schedule that queues a job by itself + Next run + When it runs next, in the server's time zone ({0}) + No runs yet + Off + Open + Show this job and its log on the Queue tab + Failed + Could not run: {0} + Queued + Its jobs were queued + Nothing to do + Not queued: there was nothing to do + Skipped: offline + Not queued: the archive was offline, or read-only for an action that writes + Skipped: busy + Not queued: its last job, or a job doing the same work, had not ended + Not available + Not queued: this server cannot run the action + Deep analysis + Deep analysis instead of the light one + Deep analysis + Also queue a deep analysis of what the scan indexes + Report only + List what maintenance would do without changing anything + Full scan + Read every file again instead of only those added or changed + Copies kept + How many copies of the index are kept; older ones are deleted + Make again + Make them again for every sequence, also those that have them + Older than (days) + What is older than this many days is removed; 0 keeps everything + Share per run (%) + Share of the archive's sequences checked per run, the least recently checked first + Steps + Unchecked for (days) + Only sequences not checked for this many days; 0 checks any + Priority + Priority of the jobs it queues + This server has no handler for this action + The index has no file to copy + The index is on PostgreSQL: back it up with PostgreSQL's own tools + The archive makes no proxies + This server cannot run this action + Repeat + How often the schedule runs + Reset + Put this system schedule back to its default settings + Reset {0}? + Run now + Queue its jobs now; the next run stays as it is + Show or hide the jobs it queued + Runs of {0} + Audit log + Audit entries older than the age limit + Job history + Finished jobs older than the age limit + Trash report + List the trash entries older than the age limit in the job log; nothing is deleted + Uploads + Abandoned uploads and their files, upload records older than the age limit and expired sign-ins + System + Archive scan + Audit log clean-up + Job history clean-up + Index backup + A task of the server itself: it can be changed, turned off and reset, not deleted + Upload clean-up + Time + Time of day, in the server's time zone ({0}) + Times in {0} + days + hours + minutes + Unit of the interval + {0} at {1} + When + When it runs; times are in the server's time zone ({0}) About Keep audit (days) Days audit entries are kept before the housekeeping deletes them; 0: forever @@ -292,8 +449,6 @@ Port of the admin panel and API over HTTP HTTPS port Port of the API over TLS for Chronos clients - Job history (days) - Days finished jobs are kept Level of “{0}” in the priority queue: a higher level runs first and pauses lower ones Jobs Language @@ -334,7 +489,7 @@ Not via proxy TLS mode is Reverse proxy, but this page did not come through a trusted proxy over HTTPS. Open it through your proxy, or add the proxy's address to CHRONOS_TRUSTED_PROXIES. Restart required - Saved ports, TLS, workers, chunk size or job history apply after a restart + Saved ports, TLS or chunk size apply after a restart Daily Hourly Server diff --git a/i18n/en/Server.resx b/i18n/en/Server.resx index 116fce30..cac724be 100644 --- a/i18n/en/Server.resx +++ b/i18n/en/Server.resx @@ -60,6 +60,7 @@ The priority must be background, normal or user.long The proxy is not a JPEG the server can read.long The role must be admin, editor, uploader or viewer.long + The schedule field {0} is not valid.long The setting {0} is not valid.long The settings must be valid JSON.long The job cannot do that in its current state.long @@ -81,6 +82,9 @@ Too many attempts; wait a minute and try again.long This render is already filed under another sequence.long Choose a password different from the current one.long + Only a system schedule can be reset to its defaults.long + The schedule's last job has not ended yet; try again when it has.long + A system schedule cannot be deleted; turn it off instead.long You cannot do this to your own account.long A job is working on this sequence or its archive; try again when it is free.long The session expired; sign in again.long @@ -105,6 +109,7 @@ Server Status {0} ms + Uploads expired: {0}, files removed: {1}, records removed: {2}, tokens removed: {3}long: job log line Cancel Password Sign in diff --git a/i18n/es/Admin.es.resx b/i18n/es/Admin.es.resx index aa2b13a2..cf1b0c10 100644 --- a/i18n/es/Admin.es.resx +++ b/i18n/es/Admin.es.resx @@ -283,8 +283,6 @@ Puerto del panel de administración y de la API por HTTP Puerto HTTPS Puerto de la API por TLS para los clientes de Chronos - Historial de tareas (días) - Días que se conservan las tareas terminadas Nivel de «{0}» en la cola de prioridad: un nivel superior se ejecuta primero y pausa los inferiores Tareas Idioma @@ -306,7 +304,6 @@ Sin proxy El modo TLS es Proxy inverso, pero esta página no llegó a través de un proxy de confianza por HTTPS. Ábrela a través de tu proxy o añade la dirección del proxy a CHRONOS_TRUSTED_PROXIES. Reinicio necesario - Los cambios guardados de puertos, TLS, ejecutores, tamaño de fragmento o historial de tareas se aplican tras reiniciar Servidor Nombre del servidor Nombre que ven los clientes y que aparece en la red local diff --git a/i18n/et/Admin.et.resx b/i18n/et/Admin.et.resx index c7f4dbe0..0033c3d5 100644 --- a/i18n/et/Admin.et.resx +++ b/i18n/et/Admin.et.resx @@ -283,8 +283,6 @@ Halduspaneeli ja API port HTTP kaudu HTTPS-port Chronose klientide API port TLS-i kaudu - Tööde ajalugu (päevi) - Mitu päeva lõpetatud töid säilitatakse Tööliigi „{0}“ tase prioriteedijärjekorras: kõrgem tase käivitub esimesena ja peatab madalamad Tööd Keel @@ -306,7 +304,6 @@ Pole puhverserveri kaudu TLS-režiim on „Pöördpuhverserver“, kuid seda lehte ei edastatud usaldusväärse puhverserveri vahendusel HTTPS-i kaudu. Avage leht oma puhverserveri kaudu või lisage puhverserveri aadress muutujasse CHRONOS_TRUSTED_PROXIES. Vajab taaskäivitust - Salvestatud pordid, TLS, töölõimed, tüki suurus ja tööde ajalugu rakenduvad pärast taaskäivitust Server Serveri nimi Klientidele ja kohtvõrgus kuvatav nimi diff --git a/i18n/fi/Admin.fi.resx b/i18n/fi/Admin.fi.resx index 3f54379e..41116b98 100644 --- a/i18n/fi/Admin.fi.resx +++ b/i18n/fi/Admin.fi.resx @@ -283,8 +283,6 @@ Hallintapaneelin ja API:n portti HTTP-yhteydellä HTTPS-portti TLS-suojatun API:n portti Chronos-asiakasohjelmille - Työhistoria (päivää) - Montako päivää valmiit työt säilytetään Työn ”{0}” taso prioriteettijonossa: korkeampi taso suoritetaan ensin ja keskeyttää alemmat Työt Kieli @@ -306,7 +304,6 @@ Ei välityspalvelimen kautta TLS-tila on Käänteinen välityspalvelin, mutta tämä sivu ei tullut luotetun välityspalvelimen kautta HTTPS-yhteydellä. Avaa sivu välityspalvelimesi kautta tai lisää välityspalvelimen osoite muuttujaan CHRONOS_TRUSTED_PROXIES. Uudelleenkäynnistys tarvitaan - Tallennetut portit, TLS, suorittajat, lohkon koko ja työhistoria tulevat voimaan uudelleenkäynnistyksen jälkeen Palvelin Palvelimen nimi Asiakasohjelmille ja lähiverkossa näytettävä nimi diff --git a/i18n/fr/Admin.fr.resx b/i18n/fr/Admin.fr.resx index 1dbba572..c376dcaa 100644 --- a/i18n/fr/Admin.fr.resx +++ b/i18n/fr/Admin.fr.resx @@ -283,8 +283,6 @@ Port du panneau d'administration et de l'API en HTTP Port HTTPS Port de l'API en TLS pour les clients Chronos - Historique des tâches (jours) - Nombre de jours de conservation des tâches terminées Niveau de « {0} » dans la file de priorité : un niveau supérieur passe en premier et suspend les niveaux inférieurs Tâches Langue @@ -306,7 +304,6 @@ Sans proxy Le mode TLS est « Proxy inverse », mais cette page n'est pas passée par un proxy approuvé en HTTPS. Ouvrez-la via votre proxy ou ajoutez l'adresse du proxy à CHRONOS_TRUSTED_PROXIES. Redémarrage requis - Les ports, le TLS, les exécuteurs, la taille des blocs ou l'historique des tâches enregistrés s'appliquent après un redémarrage Serveur Nom du serveur Nom affiché aux clients et sur le réseau local diff --git a/i18n/he/Admin.he.resx b/i18n/he/Admin.he.resx index d41a4c3e..5949df79 100644 --- a/i18n/he/Admin.he.resx +++ b/i18n/he/Admin.he.resx @@ -296,8 +296,6 @@ היציאה של ממשק הניהול ושל ה-API ב-HTTP יציאת HTTPS היציאה של ה-API ב-TLS עבור לקוחות Chronos - היסטוריית משימות (ימים) - מספר הימים שבהם נשמרות משימות שהסתיימו הרמה של "{0}" בתור העדיפויות: רמה גבוהה יותר פועלת קודם ומשהה רמות נמוכות יותר משימות שפה @@ -319,7 +317,6 @@ לא דרך הפרוקסי מצב ה-TLS הוא "פרוקסי הפוך", אך הדף הזה לא הגיע דרך פרוקסי מהימן ב-HTTPS. יש לפתוח אותו דרך הפרוקסי, או להוסיף את כתובת הפרוקסי ל-CHRONOS_TRUSTED_PROXIES. נדרשת הפעלה מחדש - שינויים שנשמרו ביציאות, ב-TLS, בתהליכי העבודה, בגודל המקטע או בהיסטוריית המשימות ייכנסו לתוקף לאחר הפעלה מחדש שרת שם השרת השם שמוצג ללקוחות וברשת המקומית diff --git a/i18n/hi/Admin.hi.resx b/i18n/hi/Admin.hi.resx index b1dc458b..d1e31202 100644 --- a/i18n/hi/Admin.hi.resx +++ b/i18n/hi/Admin.hi.resx @@ -283,8 +283,6 @@ HTTP पर व्यवस्थापक पैनल और API का पोर्ट HTTPS पोर्ट Chronos क्लाइंट के लिए TLS पर API का पोर्ट - कार्य इतिहास (दिन) - पूर्ण कार्य कितने दिन रखे जाते हैं प्राथमिकता कतार में “{0}” का स्तर: उच्च स्तर पहले चलता है और निचले स्तरों को विराम देता है कार्य भाषा @@ -306,7 +304,6 @@ बिना प्रॉक्सी TLS मोड रिवर्स प्रॉक्सी है, लेकिन यह पेज HTTPS पर किसी विश्वसनीय प्रॉक्सी से होकर नहीं आया। इसे अपने प्रॉक्सी के ज़रिए खोलें, या प्रॉक्सी का पता CHRONOS_TRUSTED_PROXIES में जोड़ें। पुनरारंभ आवश्यक - सहेजे गए पोर्ट, TLS, वर्कर, खंड आकार या कार्य इतिहास पुनरारंभ के बाद लागू होते हैं सर्वर सर्वर नाम क्लाइंट को और LAN पर दिखाया जाने वाला नाम diff --git a/i18n/hr/Admin.hr.resx b/i18n/hr/Admin.hr.resx index 37cca618..4ed85bf3 100644 --- a/i18n/hr/Admin.hr.resx +++ b/i18n/hr/Admin.hr.resx @@ -296,8 +296,6 @@ Priključak administratorske ploče i API-ja preko HTTP-a HTTPS priključak Priključak API-ja preko TLS-a za klijente Chronos - Povijest zadataka (dani) - Broj dana tijekom kojih se čuvaju dovršeni zadaci Razina za „{0}” u prioritetnom redu čekanja: viša razina izvodi se prva i pauzira niže razine Zadaci Jezik @@ -319,7 +317,6 @@ Bez proxyja Način TLS-a je „Obrnuti proxy”, ali ova stranica nije stigla preko pouzdanog proxyja putem HTTPS-a. Otvorite je preko svojeg proxyja ili dodajte adresu proxyja u CHRONOS_TRUSTED_PROXIES. Potrebno ponovno pokretanje - Spremljeni priključci, TLS, radni procesi, veličina bloka i povijest zadataka primjenjuju se nakon ponovnog pokretanja Poslužitelj Naziv poslužitelja Naziv koji se prikazuje klijentima i u lokalnoj mreži diff --git a/i18n/hu/Admin.hu.resx b/i18n/hu/Admin.hu.resx index 7ffc7867..514d4a18 100644 --- a/i18n/hu/Admin.hu.resx +++ b/i18n/hu/Admin.hu.resx @@ -283,8 +283,6 @@ A felügyeleti panel és az API portja HTTP-n HTTPS-port Az API TLS-portja a Chronos kliensek számára - Feladatelőzmények (nap) - Ennyi napig maradnak meg a befejezett feladatok „{0}” szintje a prioritásos várólistán: a magasabb szint előbb fut, és szünetelteti az alacsonyabbakat Feladatok Nyelv @@ -306,7 +304,6 @@ Proxy nélkül A TLS-mód Fordított proxy, de ez az oldal nem egy megbízható proxyn keresztül, HTTPS-en érkezett. Nyissa meg a proxyn keresztül, vagy adja hozzá a proxy címét a CHRONOS_TRUSTED_PROXIES változóhoz. Újraindítás szükséges - A mentett portok, TLS, feldolgozók, blokkméret és feladatelőzmények újraindítás után lépnek érvénybe Szerver Szervernév A kliensekben és a helyi hálózaton megjelenő név diff --git a/i18n/id/Admin.id.resx b/i18n/id/Admin.id.resx index 2b705b5a..3cf6613a 100644 --- a/i18n/id/Admin.id.resx +++ b/i18n/id/Admin.id.resx @@ -283,8 +283,6 @@ Port panel admin dan API melalui HTTP Port HTTPS Port API melalui TLS untuk klien Chronos - Riwayat tugas (hari) - Jumlah hari tugas yang selesai disimpan Tingkat “{0}” dalam antrean prioritas: tingkat yang lebih tinggi berjalan lebih dulu dan menjeda tingkat yang lebih rendah Tugas Bahasa @@ -306,7 +304,6 @@ Tidak melalui proksi Mode TLS adalah Proksi balik, tetapi halaman ini tidak datang melalui proksi tepercaya lewat HTTPS. Buka halaman ini melalui proksi Anda, atau tambahkan alamat proksi ke CHRONOS_TRUSTED_PROXIES. Perlu dimulai ulang - Port, TLS, pekerja, ukuran potongan, atau riwayat tugas yang disimpan berlaku setelah server dimulai ulang Server Nama server Nama yang ditampilkan ke klien dan di LAN diff --git a/i18n/it/Admin.it.resx b/i18n/it/Admin.it.resx index 153530bf..5866a015 100644 --- a/i18n/it/Admin.it.resx +++ b/i18n/it/Admin.it.resx @@ -15,6 +15,11 @@ accesso fallito come {0} {0} ha cambiato la propria password {0} ha reimpostato la password di {1} + {0} ha creato la pianificazione {1}long + {0} ha eliminato la pianificazione {1}long + {0} ha ripristinato la pianificazione {1}long + {0} ha eseguito la pianificazione {1}long + {0} ha modificato la pianificazione {1}long {0} ha creato {1} {0} ha eliminato {1} {0} ha modificato una sequenza · {1} @@ -183,10 +188,16 @@ Rimetti in coda il job dall'ultimo punto di controllo {0} in corso {0} in corso + Pianificato + Messo in coda da una pianificazione: mostrala nella scheda Pianificati server Mostra tutti Mostra i job in ogni stato Stato + Coda + Job in attesa, in corso e terminati, e i nodi di rendering + Pianificati + Job che il server mette in coda da solo secondo una pianificazione: visualizzali, creali e modificali Oggetto Lingua di questo pannello Nome utente o password errati. @@ -203,6 +214,11 @@ Accesso fallito Password cambiata Password reimpostata + Pianificazione creata + Pianificazione eliminata + Pianificazione ripristinata + Pianificazione eseguita + Pianificazione modificata Sequenza creata Sequenza eliminata Sequenza modificata @@ -274,6 +290,147 @@ Editor Caricamento Lettore + Azione + Analisi + Analizza le sequenze senza un'analisi aggiornata + Copia dell'indice + Copia l'indice nella cartella dei backup e conserva le copie più recenti + Pulizia + Rimuove la vecchia cronologia dei job, le voci di controllo e ciò che i caricamenti hanno lasciato + Rapporto duplicati + Elenca le foto duplicate nel log del job; non cambia nulla + Manutenzione + Rimuove blocchi scaduti e file temporanei e compatta i pacchetti e l'indice dell'archivio + Rapporto orfani + Elenca nel log del job dove indice e disco non concordano; non cambia nulla + Proxy + Crea i proxy che mancano alle sequenze, se l'archivio crea proxy + Scansione archivio + Indicizza le foto aggiunte o modificate nella cartella dell'archivio + Miniature + Crea le miniature che mancano alle sequenze + Cosa fa la pianificazione quando parte + Verifica integrità + Legge gli originali e li confronta con i loro hash, partendo da quelli verificati meno di recente + Recupera + Parte una volta all'avvio se un'esecuzione è saltata mentre il server era spento + {0} pianificazione + {0} pianificazioni + Crea + Crea questa pianificazione + Ogni giorno alle {0} + Parte di {0} + Giorno del mese + Giorno del mese in cui parte, da 1 a 28 + Giorni + Elimina + Elimina questa pianificazione; i job che ha messo in coda restano nella cronologia + Eliminare {0}? + Modifica + Cambia quando e come parte questa pianificazione + Modifica pianificazione + Nessuna pianificazione + Attiva + Attiva, la pianificazione parte da sola; disattivata, parte solo con Esegui ora + Attiva: {0} + Ogni giorno + Ogni {0} giorni + Ogni ora + Ogni {0} ore + Ogni minuto + Ogni {0} minuti + Una pianificazione di sistema mantiene nome e azione + Ogni + Tempo tra due esecuzioni: almeno 5 minuti, al massimo 1440 minuti, 168 ore o 366 giorni + Ogni giorno + A intervalli + Ogni mese + Ogni settimana + Ultimo esito + Il giorno {0} di ogni mese alle {1} + Nome + Un nome per riconoscere la pianificazione + Mai eseguita + Nuova pianificazione + Crea una pianificazione che mette in coda un job da sola + Prossima + Quando parte la prossima volta, nel fuso orario del server ({0}) + Nessuna esecuzione + Disattivata + Apri + Mostra questo job e il suo log nella scheda Coda + Non riuscita + Non è partita: {0} + In coda + I suoi job sono stati messi in coda + Niente da fare + Nulla in coda: non c'era niente da fare + Saltata: offline + Nulla in coda: l'archivio era offline, o in sola lettura per un'azione che scrive + Saltata: occupata + Nulla in coda: il suo ultimo job, o un job che fa lo stesso lavoro, non era terminato + Non disponibile + Nulla in coda: questo server non può eseguire l'azione + Analisi completa + Analisi completa invece di quella rapida + Analisi completa + Mette in coda anche un'analisi completa di ciò che la scansione indicizza + Solo rapporto + Elenca cosa farebbe la manutenzione senza cambiare nulla + Scansione completa + Rilegge ogni file invece di quelli aggiunti o modificati + Copie conservate + Quante copie dell'indice si conservano; le più vecchie vengono eliminate + Ricrea + Le ricrea per ogni sequenza, anche per quelle che le hanno + Più vecchi di (giorni) + Ciò che è più vecchio di questi giorni viene rimosso; 0 conserva tutto + Quota per volta (%) + Quota delle sequenze dell'archivio verificate a ogni esecuzione, partendo da quelle verificate meno di recente + Passaggi + Non verificate da (giorni) + Solo le sequenze non verificate da questi giorni; 0 le prende tutte + Priorità + Priorità dei job che mette in coda + Questo server non ha un gestore per questa azione + L'indice non ha un file da copiare + L'indice è su PostgreSQL: fanne il backup con gli strumenti di PostgreSQL + L'archivio non crea proxy + Questo server non può eseguire questa azione + Ripeti + Ogni quanto parte la pianificazione + Ripristina + Riporta questa pianificazione di sistema alle impostazioni predefinite + Ripristinare {0}? + Esegui ora + Mette in coda ora i suoi job; la prossima esecuzione resta com'è + Mostra o nascondi i job che ha messo in coda + Esecuzioni di {0} + Registro di controllo + Voci di controllo più vecchie del limite + Cronologia job + Job terminati più vecchi del limite + Rapporto cestino + Elenca nel log del job le voci del cestino più vecchie del limite; non elimina nulla + Caricamenti + Caricamenti abbandonati e i loro file, record di caricamento più vecchi del limite e accessi scaduti + Sistema + Scansione archivio + Pulizia registro controllo + Pulizia cronologia job + Copia dell'indice + Un'attività del server stesso: si può modificare, disattivare e ripristinare, non eliminare + Pulizia caricamenti + Ora + Ora del giorno, nel fuso orario del server ({0}) + Orari in {0} + giorni + ore + minuti + Unità dell'intervallo + {0} alle {1} + Quando + Quando parte; gli orari sono nel fuso orario del server ({0}) Informazioni Conserva controllo (giorni) Giorni di conservazione delle voci di controllo prima che la manutenzione le elimini; 0: per sempre @@ -291,8 +448,6 @@ Porta del pannello e delle API in HTTP Porta HTTPS Porta delle API in TLS per i client Chronos - Cronologia job (giorni) - Giorni di conservazione dei job conclusi Livello di «{0}» nella coda di priorità: un livello più alto parte prima e mette in pausa quelli più bassi Attività Lingua @@ -333,7 +488,7 @@ Senza proxy La modalità TLS è Reverse proxy, ma questa pagina non è arrivata da un proxy attendibile in HTTPS. Aprila tramite il proxy o aggiungi l'indirizzo del proxy a CHRONOS_TRUSTED_PROXIES. Riavvio richiesto - Porte, TLS, worker, dimensione blocchi o cronologia job salvati valgono dopo un riavvio + Porte, TLS o dimensione blocchi salvati valgono dopo un riavvio Giornaliera Oraria Server diff --git a/i18n/it/Server.it.resx b/i18n/it/Server.it.resx index 0515525e..febc22da 100644 --- a/i18n/it/Server.it.resx +++ b/i18n/it/Server.it.resx @@ -58,6 +58,7 @@ La priorità deve essere background, normal o user. Il proxy non è un JPEG che il server sa leggere. Il ruolo deve essere admin, editor, uploader o viewer. + Il campo {0} della pianificazione non è valido.long L'impostazione {0} non è valida. Le impostazioni devono essere JSON valido. Il job non può farlo nello stato attuale. @@ -79,6 +80,9 @@ Troppi tentativi; attendi un minuto e riprova. Questo render è già archiviato in un'altra sequenza. Scegli una password diversa da quella attuale. + Solo una pianificazione di sistema si può riportare ai valori predefiniti.long + L'ultimo job della pianificazione non è ancora terminato; riprova quando avrà finito.long + Una pianificazione di sistema non si può eliminare; disattivala.long Non puoi farlo sul tuo account. Un'attività sta lavorando su questa sequenza o sul suo archivio; riprova quando è libera. La sessione è scaduta; accedi di nuovo. @@ -103,6 +107,7 @@ Server Stato {0} ms + Caricamenti scaduti: {0}, file rimossi: {1}, record rimossi: {2}, token rimossi: {3}long: job log line Annulla Password Accedi diff --git a/i18n/ja/Admin.ja.resx b/i18n/ja/Admin.ja.resx index de302140..b24f7622 100644 --- a/i18n/ja/Admin.ja.resx +++ b/i18n/ja/Admin.ja.resx @@ -283,8 +283,6 @@ HTTP で提供する管理パネルと API のポートです。 HTTPS ポート Chronos クライアント向けに TLS で提供する API のポートです。 - ジョブ履歴 (日数) - 完了したジョブを保持する日数です。 優先度キューにおける「{0}」のレベルです。上位レベルが先に実行され、下位レベルを一時停止します。 ジョブ 言語 @@ -306,7 +304,6 @@ プロキシ未経由 TLS モードは「リバースプロキシ」ですが、このページは信頼済みのプロキシから HTTPS 経由で届いていません。プロキシ経由で開くか、プロキシのアドレスを CHRONOS_TRUSTED_PROXIES に追加してください。 再起動が必要 - 保存したポート、TLS、ワーカー、チャンクサイズ、ジョブ履歴は再起動後に適用されます。 サーバー サーバー名 クライアントと LAN 上に表示される名前です。 diff --git a/i18n/ko/Admin.ko.resx b/i18n/ko/Admin.ko.resx index 65db1720..f3434c76 100644 --- a/i18n/ko/Admin.ko.resx +++ b/i18n/ko/Admin.ko.resx @@ -283,8 +283,6 @@ HTTP를 통한 관리 패널 및 API의 포트 HTTPS 포트 Chronos 클라이언트용 TLS를 통한 API의 포트 - 작업 기록(일) - 완료된 작업을 보관하는 일수 우선순위 대기열에서 ‘{0}’의 수준입니다. 상위 수준이 먼저 실행되며 하위 수준을 일시 중지합니다. 작업 언어 @@ -306,7 +304,6 @@ 프록시 미경유 TLS 모드가 ‘역방향 프록시’이지만 이 페이지는 신뢰하는 프록시를 거쳐 HTTPS로 전달되지 않았습니다. 사용 중인 프록시를 통해 이 페이지를 열거나 프록시 주소를 CHRONOS_TRUSTED_PROXIES에 추가하십시오. 다시 시작 필요 - 저장한 포트, TLS, 워커, 청크 크기, 작업 기록 설정은 다시 시작한 후에 적용됩니다. 서버 서버 이름 클라이언트와 LAN에 표시되는 이름 diff --git a/i18n/lt/Admin.lt.resx b/i18n/lt/Admin.lt.resx index 8de8fdc3..7298e4db 100644 --- a/i18n/lt/Admin.lt.resx +++ b/i18n/lt/Admin.lt.resx @@ -296,8 +296,6 @@ Administravimo skydelio ir API prievadas per HTTP HTTPS prievadas API prievadas per TLS Chronos klientams - Užduočių istorija (d.) - Kiek dienų saugomos baigtos užduotys Užduoties „{0}“ lygis prioritetinėje eilėje: aukštesnis lygis vykdomas pirmiau ir pristabdo žemesnius Užduotys Kalba @@ -319,7 +317,6 @@ Be tarpinio serverio TLS režimas – „Atvirkštinis tarpinis serveris“, bet šis puslapis gautas ne per patikimą tarpinį serverį HTTPS ryšiu. Atidarykite jį per savo tarpinį serverį arba įtraukite tarpinio serverio adresą į CHRONOS_TRUSTED_PROXIES. Reikia paleisti iš naujo - Įrašyti prievadai, TLS, vykdytojai, dalies dydis ar užduočių istorija įsigalioja paleidus iš naujo Serveris Serverio pavadinimas Pavadinimas, rodomas klientams ir vietiniame tinkle diff --git a/i18n/lv/Admin.lv.resx b/i18n/lv/Admin.lv.resx index 26cfd6b6..bdd991d1 100644 --- a/i18n/lv/Admin.lv.resx +++ b/i18n/lv/Admin.lv.resx @@ -296,8 +296,6 @@ Administrēšanas paneļa un API ports, izmantojot HTTP HTTPS ports API ports Chronos klientiem, izmantojot TLS - Darbu vēsture (dienas) - Cik dienas glabāt pabeigtos darbus Darba „{0}” līmenis prioritāšu rindā: augstāks līmenis tiek izpildīts pirmais un pauzē zemākos Darbi Valoda @@ -319,7 +317,6 @@ Bez starpniekservera TLS režīms ir „Reversais starpniekserveris”, taču šī lapa netika atvērta caur uzticamu starpniekserveri, izmantojot HTTPS. Atveriet to caur savu starpniekserveri vai pievienojiet starpniekservera adresi mainīgajam CHRONOS_TRUSTED_PROXIES. Jārestartē - Saglabātie porti, TLS, izpildītāji, daļas lielums un darbu vēsture stājas spēkā pēc restartēšanas Serveris Servera nosaukums Nosaukums, ko redz klienti un lokālais tīkls diff --git a/i18n/ms/Admin.ms.resx b/i18n/ms/Admin.ms.resx index 4ff3e6c3..4bba11be 100644 --- a/i18n/ms/Admin.ms.resx +++ b/i18n/ms/Admin.ms.resx @@ -283,8 +283,6 @@ Port panel pentadbir dan API melalui HTTP Port HTTPS Port API melalui TLS untuk klien Chronos - Sejarah tugas (hari) - Bilangan hari tugas yang selesai disimpan Peringkat “{0}” dalam baris gilir keutamaan: peringkat lebih tinggi berjalan dahulu dan menjeda peringkat yang lebih rendah Tugas Bahasa @@ -306,7 +304,6 @@ Tidak melalui proksi Mod TLS ialah Proksi songsang, tetapi halaman ini tidak diterima daripada proksi yang dipercayai melalui HTTPS. Buka halaman ini melalui proksi anda, atau tambahkan alamat proksi itu pada CHRONOS_TRUSTED_PROXIES. Perlu mula semula - Port, TLS, pekerja, saiz cebisan atau sejarah tugas yang disimpan berkuat kuasa selepas mula semula Pelayan Nama pelayan Nama yang ditunjukkan kepada klien dan pada LAN diff --git a/i18n/nb/Admin.nb.resx b/i18n/nb/Admin.nb.resx index 31db9aac..cfd63c17 100644 --- a/i18n/nb/Admin.nb.resx +++ b/i18n/nb/Admin.nb.resx @@ -283,8 +283,6 @@ Port for administrasjonspanelet og API-et over HTTP HTTPS-port Port for API-et over TLS for Chronos-klienter - Jobbhistorikk (dager) - Antall dager fullførte jobber beholdes Nivået til «{0}» i prioritetskøen: et høyere nivå kjører først og setter lavere nivåer på pause Jobber Språk @@ -306,7 +304,6 @@ Ikke via proxy TLS-modusen er Omvendt proxy, men denne siden kom ikke gjennom en klarert proxy over HTTPS. Åpne den gjennom proxyen din, eller legg til proxyens adresse i CHRONOS_TRUSTED_PROXIES. Omstart kreves - Lagrede endringer i porter, TLS, arbeidsprosesser, blokkstørrelse eller jobbhistorikk trer i kraft etter en omstart Server Servernavn Navnet som vises for klienter og på det lokale nettverket diff --git a/i18n/nl/Admin.nl.resx b/i18n/nl/Admin.nl.resx index 1430ca14..4fa190b4 100644 --- a/i18n/nl/Admin.nl.resx +++ b/i18n/nl/Admin.nl.resx @@ -283,8 +283,6 @@ Poort van het beheerpaneel en de API via HTTP HTTPS-poort Poort van de API via TLS voor Chronos-clients - Taakgeschiedenis (dagen) - Aantal dagen dat voltooide taken worden bewaard Niveau van “{0}” in de prioriteitswachtrij: een hoger niveau gaat eerst en onderbreekt lagere niveaus Taken Taal @@ -306,7 +304,6 @@ Niet via proxy De TLS-modus is Reverse proxy, maar deze pagina is niet via een vertrouwde proxy over HTTPS binnengekomen. Open de pagina via je proxy of voeg het adres van de proxy toe aan CHRONOS_TRUSTED_PROXIES. Opnieuw opstarten vereist - Opgeslagen poorten, TLS, werkprocessen, blokgrootte of taakgeschiedenis gelden na opnieuw opstarten Server Servernaam Naam die wordt getoond aan clients en op het lokale netwerk diff --git a/i18n/pl/Admin.pl.resx b/i18n/pl/Admin.pl.resx index abd3bc56..39017b14 100644 --- a/i18n/pl/Admin.pl.resx +++ b/i18n/pl/Admin.pl.resx @@ -309,8 +309,6 @@ Port panelu administracyjnego i API przez HTTP Port HTTPS Port API przez TLS dla klientów Chronos - Historia zadań (dni) - Liczba dni przechowywania zakończonych zadań Poziom „{0}” w kolejce priorytetowej: wyższy poziom jest wykonywany jako pierwszy i wstrzymuje niższe Zadania Język @@ -332,7 +330,6 @@ Bez serwera proxy Tryb TLS to „Zwrotny serwer proxy”, ale ta strona nie dotarła przez zaufany serwer proxy połączeniem HTTPS. Otwórz ją przez swój serwer proxy lub dodaj jego adres do CHRONOS_TRUSTED_PROXIES. Wymagane ponowne uruchomienie - Zapisane porty, TLS, procesy robocze, rozmiar fragmentu i historia zadań zaczną obowiązywać po ponownym uruchomieniu Serwer Nazwa serwera Nazwa wyświetlana klientom i w sieci LAN diff --git a/i18n/pt-BR/Admin.pt-BR.resx b/i18n/pt-BR/Admin.pt-BR.resx index 1f659d29..83c80034 100644 --- a/i18n/pt-BR/Admin.pt-BR.resx +++ b/i18n/pt-BR/Admin.pt-BR.resx @@ -283,8 +283,6 @@ Porta do painel de administração e da API via HTTP Porta HTTPS Porta da API via TLS para os clientes Chronos - Histórico de tarefas (dias) - Dias em que as tarefas concluídas são mantidas Nível de “{0}” na fila de prioridade: um nível mais alto é executado primeiro e pausa os mais baixos Tarefas Idioma @@ -306,7 +304,6 @@ Sem proxy O modo TLS é Proxy reverso, mas esta página não chegou por um proxy confiável via HTTPS. Abra-a pelo seu proxy ou adicione o endereço do proxy a CHRONOS_TRUSTED_PROXIES. Reinicialização necessária - Portas, TLS, processos, tamanho de bloco ou histórico de tarefas salvos entram em vigor após a reinicialização Servidor Nome do servidor Nome exibido aos clientes e na LAN diff --git a/i18n/pt-PT/Admin.pt-PT.resx b/i18n/pt-PT/Admin.pt-PT.resx index 6282a1c2..b8521416 100644 --- a/i18n/pt-PT/Admin.pt-PT.resx +++ b/i18n/pt-PT/Admin.pt-PT.resx @@ -283,8 +283,6 @@ Porta do painel de administração e da API por HTTP Porta HTTPS Porta da API por TLS para os clientes Chronos - Histórico de tarefas (dias) - Dias durante os quais as tarefas terminadas são mantidas Nível de «{0}» na fila de prioridade: um nível superior é executado primeiro e pausa os inferiores Tarefas Idioma @@ -306,7 +304,6 @@ Sem proxy O modo TLS é Proxy inverso, mas esta página não chegou através de um proxy fidedigno por HTTPS. Abra-a através do seu proxy ou adicione o endereço do proxy a CHRONOS_TRUSTED_PROXIES. Reinício necessário - As alterações guardadas às portas, ao TLS, aos processos, ao tamanho do bloco ou ao histórico de tarefas aplicam-se após um reinício Servidor Nome do servidor Nome apresentado aos clientes e na LAN diff --git a/i18n/ro/Admin.ro.resx b/i18n/ro/Admin.ro.resx index 90d4f3d5..a804cdfc 100644 --- a/i18n/ro/Admin.ro.resx +++ b/i18n/ro/Admin.ro.resx @@ -296,8 +296,6 @@ Portul panoului de administrare și al API-ului prin HTTP Port HTTPS Portul API-ului prin TLS pentru clienții Chronos - Istoric lucrări (zile) - Numărul de zile în care sunt păstrate lucrările încheiate Nivelul pentru „{0}” în coada cu priorități: un nivel superior rulează primul și pune pe pauză nivelurile inferioare Lucrări Limbă @@ -319,7 +317,6 @@ Fără proxy Modul TLS este Proxy invers, dar această pagină nu a sosit prin HTTPS de la un proxy de încredere. Deschideți-o prin proxy-ul dumneavoastră sau adăugați adresa proxy-ului în CHRONOS_TRUSTED_PROXIES. Repornire necesară - Modificările salvate la porturi, TLS, procese de lucru, dimensiunea blocului sau istoricul lucrărilor se aplică după o repornire Server Nume server Numele afișat clienților și în rețeaua locală diff --git a/i18n/ru/Admin.ru.resx b/i18n/ru/Admin.ru.resx index e1d6f8c3..c3fe9314 100644 --- a/i18n/ru/Admin.ru.resx +++ b/i18n/ru/Admin.ru.resx @@ -309,8 +309,6 @@ Порт панели администрирования и API по HTTP Порт HTTPS Порт API по TLS для клиентов Chronos - История заданий (дн.) - Сколько дней хранятся завершённые задания Уровень «{0}» в очереди с приоритетами: более высокий уровень выполняется первым и приостанавливает более низкие Задания Язык @@ -332,7 +330,6 @@ Не через прокси Режим TLS — «Обратный прокси», но эта страница пришла не через доверенный прокси по HTTPS. Откройте её через свой прокси или добавьте адрес прокси в CHRONOS_TRUSTED_PROXIES. Требуется перезапуск - Сохранённые порты, TLS, обработчики, размер блока и история заданий вступают в силу после перезапуска Сервер Имя сервера Имя, которое видят клиенты и устройства в локальной сети diff --git a/i18n/sk/Admin.sk.resx b/i18n/sk/Admin.sk.resx index 87867c22..8185b2a7 100644 --- a/i18n/sk/Admin.sk.resx +++ b/i18n/sk/Admin.sk.resx @@ -296,8 +296,6 @@ Port panela správy a rozhrania API cez HTTP Port HTTPS Port rozhrania API cez TLS pre klientov Chronos - História úloh (dni) - Počet dní, počas ktorých sa uchovávajú dokončené úlohy Úroveň „{0}“ v prioritnom fronte: vyššia úroveň beží skôr a pozastavuje nižšie úrovne Úlohy Jazyk @@ -319,7 +317,6 @@ Mimo proxy Režim TLS je nastavený na Reverzný proxy server, ale táto stránka neprišla prostredníctvom dôveryhodného proxy servera cez HTTPS. Otvorte ju cez svoj proxy server alebo pridajte jeho adresu do CHRONOS_TRUSTED_PROXIES. Vyžaduje sa reštart - Uložené porty, TLS, pracovné procesy, veľkosť bloku a história úloh sa prejavia až po reštarte Server Názov servera Názov zobrazovaný klientom a v sieti LAN diff --git a/i18n/sl/Admin.sl.resx b/i18n/sl/Admin.sl.resx index 265f4eec..c4ff8ff6 100644 --- a/i18n/sl/Admin.sl.resx +++ b/i18n/sl/Admin.sl.resx @@ -296,8 +296,6 @@ Vrata skrbniške plošče in API-ja prek HTTP Vrata HTTPS Vrata API-ja prek TLS za odjemalce Chronos - Zgodovina opravil (dni) - Koliko dni se hranijo končana opravila Raven za »{0}« v prednostni čakalni vrsti: višja raven se izvede prej in začasno ustavi nižje Opravila Jezik @@ -319,7 +317,6 @@ Ne prek proxyja Način TLS je »Obratni proxy«, vendar ta stran ni prišla prek zaupanja vrednega proxyja po HTTPS. Odprite jo prek svojega proxyja ali dodajte naslov proxyja v CHRONOS_TRUSTED_PROXIES. Potreben vnovični zagon - Shranjena vrata, TLS, delovni procesi, velikost kosa ali zgodovina opravil začnejo veljati po vnovičnem zagonu Strežnik Ime strežnika Ime, ki ga vidijo odjemalci in naprave v LAN diff --git a/i18n/sv/Admin.sv.resx b/i18n/sv/Admin.sv.resx index 4735b32d..ca0c916f 100644 --- a/i18n/sv/Admin.sv.resx +++ b/i18n/sv/Admin.sv.resx @@ -283,8 +283,6 @@ Port för administratörspanelen och API över HTTP HTTPS-port Port för API över TLS för Chronos-klienter - Jobbhistorik (dagar) - Antal dagar som slutförda jobb sparas Nivån för ”{0}” i prioritetskön: en högre nivå körs först och pausar lägre nivåer Jobb Språk @@ -306,7 +304,6 @@ Inte via proxy TLS-läget är Omvänd proxy, men den här sidan kom inte via en betrodd proxy över HTTPS. Öppna den via din proxy, eller lägg till proxyns adress i CHRONOS_TRUSTED_PROXIES. Omstart krävs - Sparade ändringar av portar, TLS, arbetare, segmentstorlek eller jobbhistorik gäller efter en omstart Server Servernamn Namn som visas för klienter och i det lokala nätverket diff --git a/i18n/th/Admin.th.resx b/i18n/th/Admin.th.resx index 02a50f79..91bed582 100644 --- a/i18n/th/Admin.th.resx +++ b/i18n/th/Admin.th.resx @@ -283,8 +283,6 @@ พอร์ตของแผงผู้ดูแลระบบและ API ผ่าน HTTP พอร์ต HTTPS พอร์ตของ API ผ่าน TLS สำหรับไคลเอนต์ Chronos - ประวัติงาน (วัน) - จำนวนวันที่เก็บงานที่เสร็จแล้วไว้ ระดับของ “{0}” ในคิวตามลำดับความสำคัญ: ระดับที่สูงกว่าจะทำงานก่อนและหยุดระดับที่ต่ำกว่าชั่วคราว งาน ภาษา @@ -306,7 +304,6 @@ ไม่ผ่านพร็อกซี โหมด TLS เป็นรีเวิร์สพร็อกซี แต่หน้านี้ไม่ได้ส่งผ่านพร็อกซีที่เชื่อถือได้ทาง HTTPS โปรดเปิดผ่านพร็อกซีของคุณ หรือเพิ่มที่อยู่ของพร็อกซีลงใน CHRONOS_TRUSTED_PROXIES ต้องรีสตาร์ท - พอร์ต TLS เวิร์กเกอร์ ขนาดชิ้นส่วน หรือประวัติงานที่บันทึกแล้วจะมีผลหลังรีสตาร์ท เซิร์ฟเวอร์ ชื่อเซิร์ฟเวอร์ ชื่อที่แสดงต่อไคลเอนต์และบน LAN diff --git a/i18n/tr/Admin.tr.resx b/i18n/tr/Admin.tr.resx index 13d7f6ce..fd1cebae 100644 --- a/i18n/tr/Admin.tr.resx +++ b/i18n/tr/Admin.tr.resx @@ -283,8 +283,6 @@ HTTP üzerinden yönetim paneli ve API bağlantı noktası HTTPS bağlantı noktası Chronos istemcileri için TLS üzerinden API bağlantı noktası - Görev geçmişi (gün) - Biten görevlerin saklandığı gün sayısı “{0}” için öncelik kuyruğundaki düzey: daha yüksek düzey önce çalışır ve daha düşük düzeyleri duraklatır Görevler Dil @@ -306,7 +304,6 @@ Proxy üzerinden değil TLS modu Ters proxy olarak ayarlı, ancak bu sayfa HTTPS üzerinden güvenilen bir proxy aracılığıyla gelmedi. Sayfayı proxy'niz üzerinden açın veya proxy'nin adresini CHRONOS_TRUSTED_PROXIES değişkenine ekleyin. Yeniden başlatma gerekli - Kaydedilen bağlantı noktaları, TLS, işçiler, parça boyutu veya görev geçmişi yeniden başlatmadan sonra uygulanır Sunucu Sunucu adı İstemcilere ve yerel ağda gösterilen ad diff --git a/i18n/uk/Admin.uk.resx b/i18n/uk/Admin.uk.resx index 3f004b34..6e03fca4 100644 --- a/i18n/uk/Admin.uk.resx +++ b/i18n/uk/Admin.uk.resx @@ -309,8 +309,6 @@ Порт панелі адміністратора та API через HTTP Порт HTTPS Порт API через TLS для клієнтів Chronos - Історія завдань (днів) - Скільки днів зберігаються завершені завдання Рівень «{0}» у черзі з пріоритетами: вищий рівень виконується першим і призупиняє нижчі Завдання Мова @@ -332,7 +330,6 @@ Не через проксі Режим TLS — «Зворотний проксі», але цю сторінку отримано не через довірений проксі за протоколом HTTPS. Відкрийте її через свій проксі або додайте адресу проксі до CHRONOS_TRUSTED_PROXIES. Потрібен перезапуск - Збережені порти, TLS, обробники, розмір частин та історія завдань застосовуються після перезапуску Сервер Ім’я сервера Ім’я, яке бачать клієнти та локальна мережа diff --git a/i18n/vi/Admin.vi.resx b/i18n/vi/Admin.vi.resx index ccdf49bf..34ace583 100644 --- a/i18n/vi/Admin.vi.resx +++ b/i18n/vi/Admin.vi.resx @@ -283,8 +283,6 @@ Cổng của bảng quản trị và API qua HTTP Cổng HTTPS Cổng của API qua TLS dành cho các máy khách Chronos - Lịch sử tác vụ (ngày) - Số ngày lưu giữ các tác vụ đã hoàn tất Mức của “{0}” trong hàng đợi ưu tiên: mức cao hơn chạy trước và tạm dừng các mức thấp hơn Tác vụ Ngôn ngữ @@ -306,7 +304,6 @@ Không qua proxy Chế độ TLS là Proxy ngược, nhưng trang này không đi qua một proxy tin cậy bằng HTTPS. Hãy mở trang qua proxy của bạn, hoặc thêm địa chỉ của proxy vào CHRONOS_TRUSTED_PROXIES. Cần khởi động lại - Cổng, TLS, luồng xử lý, kích thước khối hoặc lịch sử tác vụ đã lưu sẽ có hiệu lực sau khi khởi động lại Máy chủ Tên máy chủ Tên hiển thị cho máy khách và trên mạng LAN diff --git a/i18n/zh-Hans/Admin.zh-Hans.resx b/i18n/zh-Hans/Admin.zh-Hans.resx index 8dd3561a..ad2c4431 100644 --- a/i18n/zh-Hans/Admin.zh-Hans.resx +++ b/i18n/zh-Hans/Admin.zh-Hans.resx @@ -283,8 +283,6 @@ 通过 HTTP 提供管理面板和 API 的端口 HTTPS 端口 通过 TLS 为 Chronos 客户端提供 API 的端口 - 任务历史(天) - 已完成任务的保留天数 “{0}”在优先级队列中的级别:级别较高的先运行,并暂停级别较低的 任务 语言 @@ -306,7 +304,6 @@ 未经代理 TLS 模式为“反向代理”,但此页面并非经由受信任的代理通过 HTTPS 访问。请通过你的代理打开它,或将代理的地址添加到 CHRONOS_TRUSTED_PROXIES。 需要重启 - 已保存的端口、TLS、工作线程、分块大小或任务历史设置在重启后生效 服务器 服务器名称 向客户端和局域网显示的名称 diff --git a/i18n/zh-Hant/Admin.zh-Hant.resx b/i18n/zh-Hant/Admin.zh-Hant.resx index 3f830ef5..980eed5a 100644 --- a/i18n/zh-Hant/Admin.zh-Hant.resx +++ b/i18n/zh-Hant/Admin.zh-Hant.resx @@ -283,8 +283,6 @@ 透過 HTTP 提供管理面板與 API 的連接埠 HTTPS 連接埠 透過 TLS 為 Chronos 用戶端提供 API 的連接埠 - 工作歷史記錄(天) - 已完成工作的保留天數 「{0}」在優先順序佇列中的等級:等級較高者先執行,並會暫停等級較低者 工作 語言 @@ -306,7 +304,6 @@ 未經由代理伺服器 TLS 模式為「反向代理」,但此頁面並非透過受信任的代理伺服器以 HTTPS 傳送。請透過您的代理伺服器開啟此頁面,或將代理伺服器的位址加入 CHRONOS_TRUSTED_PROXIES。 需要重新啟動 - 已儲存的連接埠、TLS、工作者、區塊大小或工作歷史記錄設定,會在重新啟動後生效 伺服器 伺服器名稱 向用戶端與區域網路顯示的名稱 diff --git a/src/Chronos.Data/Repositories/JobRepository.cs b/src/Chronos.Data/Repositories/JobRepository.cs index e415fbbe..8fbbe23e 100644 --- a/src/Chronos.Data/Repositories/JobRepository.cs +++ b/src/Chronos.Data/Repositories/JobRepository.cs @@ -216,6 +216,34 @@ public sealed class JobRepository _db.ListAsync($"SELECT {Columns} FROM jobs WHERE schedule_id = $1 ORDER BY created DESC, id DESC LIMIT $2", [scheduleId, Cursor.ClampLimit(limit)], Map, cancellationToken); + /// + /// The jobs the schedule queued, newest first, a page at a time (the runs a schedule's + /// row lists in the admin panel); continues after the previous page. + /// + public Task> PageByScheduleAsync(Guid scheduleId, int limit = 20, string? cursor = null, CancellationToken cancellationToken = default) + { + var p = new SqlParameters(); + var where = $"schedule_id = {p.Add(scheduleId)}"; + if (cursor is not null) + { + var (value, id) = Cursor.Decode("schedule-runs", cursor); + where += " AND " + Cursor.After("created", "id", descending: true, value, id, p.Add); + } + var take = Cursor.ClampLimit(limit); + var sql = $"SELECT {Columns} FROM jobs WHERE {where} ORDER BY created DESC, id DESC LIMIT {p.Add(take + 1)}"; + return _db.RunAsync(async session => + { + var jobs = await session.QueryListAsync(sql, p.ToArray(), Map, cancellationToken).ConfigureAwait(false); + string? next = null; + if (jobs.Count > take) + { + jobs.RemoveAt(take); + next = Cursor.Encode("schedule-runs", jobs[^1].Created, jobs[^1].Id); + } + return new Page(jobs, next); + }, cancellationToken); + } + /// /// Claims one specific queued job for (render nodes pick by capability); null when another /// claimer was faster or the job is no longer queued. diff --git a/src/Chronos.Protocol/Admin.cs b/src/Chronos.Protocol/Admin.cs index fe3bda7b..ee3c9ea0 100644 --- a/src/Chronos.Protocol/Admin.cs +++ b/src/Chronos.Protocol/Admin.cs @@ -3,8 +3,9 @@ namespace Chronos.Protocol; /// /// GET/PUT /api/v1/server/settings (admin): the editable part of the server configuration. Settings named in /// come from environment variables and cannot be changed here; says -/// that saved values (ports, TLS, chunk size, job history) wait for a restart. is set in -/// responses when TLS mode is proxy and the request did not come through a trusted proxy over HTTPS (ignored when saving). +/// that saved values (ports, TLS, chunk size) wait for a restart; is what the housekeeping +/// schedule is reset to (owner review 2, R10). is set in responses when TLS mode is proxy and +/// the request did not come through a trusted proxy over HTTPS (ignored when saving). /// is how many photos the running job processes at once (jobs run one at a time), and /// with the priority queue (owner review 1); both apply at once, as /// do (owner review 2, R11; a request without them keeps them as they are). diff --git a/src/Chronos.Server/Admin/web/admin.css b/src/Chronos.Server/Admin/web/admin.css index bdaeb5da..a4706f71 100644 --- a/src/Chronos.Server/Admin/web/admin.css +++ b/src/Chronos.Server/Admin/web/admin.css @@ -223,9 +223,24 @@ svg.chart .label { fill: var(--text-muted); } .table.nodes.fit-1 .col-owner, .table.nodes.fit-1 .col-heartbeat { display: none; } .table.audit.fit-1 { grid-template-columns: max-content minmax(70px, .8fr) minmax(90px, max-content) minmax(100px, 2fr); } .table.audit.fit-1 .col-from { display: none; } +/* Scheduled jobs (owner review 2, R10): name, action, when, next run, last result, switch, actions. */ +.table.schedules { grid-template-columns: minmax(130px, 1.3fr) minmax(80px, max-content) minmax(110px, 1fr) max-content minmax(90px, max-content) max-content max-content; } +.table.schedules.fit-1 { grid-template-columns: minmax(130px, 1.3fr) minmax(110px, 1fr) max-content minmax(90px, max-content) max-content max-content; } +.table.schedules.fit-1 .col-action { display: none; } +.table.schedules.fit-2 { grid-template-columns: minmax(120px, 1.3fr) minmax(100px, 1fr) max-content max-content max-content; } +.table.schedules.fit-2 .col-last { display: none; } .table-foot { display: flex; align-items: center; gap: 16px; padding: 10px 18px; font-size: 12px; } .table-foot a { white-space: nowrap; } .row-actions { display: flex; gap: 6px; justify-content: flex-end; } +/* A name with a pill after it (a system schedule, a job a schedule queued). */ +.name-cell { display: flex; align-items: center; gap: 8px; min-width: 0; } +.pill { flex: none; display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border: 1px solid var(--stroke); border-radius: 12px; font-size: 11px; color: var(--text-muted); white-space: nowrap; text-decoration: none; } +a.pill:hover { border-color: var(--accent); color: var(--accent); } +/* The runs of a schedule, under its row: kind, state, time and a link to the job. */ +.runs { display: grid; grid-template-columns: minmax(0, max-content) max-content max-content max-content; gap: 6px 18px; align-items: center; padding: 10px 18px; background: var(--bg); border-top: 1px solid var(--stroke); } +.runs .run { display: contents; } +.runs .more { grid-column: 1 / -1; justify-self: start; } +.table .row.log-row .empty { background: var(--bg); border-top: 1px solid var(--stroke); } .person { display: flex; align-items: center; gap: 10px; min-width: 0; } .stack { display: flex; flex-direction: column; min-width: 0; } .stack small { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } @@ -253,6 +268,11 @@ pre.log.tall { max-height: 60vh; border-top: 0; } .form legend { color: var(--text-muted); margin-bottom: 8px; padding: 0; } .form h2 { font-size: 16px; } .inline { display: flex; align-items: center; gap: 8px; } +.form-group { display: grid; gap: 12px; } +.form-group:empty { display: none; } +.days { display: flex; flex-wrap: wrap; gap: 8px 14px; } +/* Each tab of a page draws into its own body; its children lay out as the page's own. */ +.tab-body { display: contents; } .buttons { display: flex; gap: 8px; justify-content: flex-end; } .error { color: var(--error); min-height: 18px; } .settings { display: grid; gap: 20px; } diff --git a/src/Chronos.Server/Admin/web/audit.js b/src/Chronos.Server/Admin/web/audit.js index d5b73f5d..097d86bd 100644 --- a/src/Chronos.Server/Admin/web/audit.js +++ b/src/Chronos.Server/Admin/web/audit.js @@ -3,6 +3,7 @@ import { t, has, plural } from "./i18n.js"; import { formatBytes } from "./ui.js"; import { kindLabel, pascal } from "./jobs.js"; +import { actionLabel as scheduleAction, outcomeLabel } from "./schedules.js"; export function actionLabel(action) { const key = `Admin.Logs.Action.${pascal(action)}`; @@ -35,6 +36,18 @@ export function detailText(entry) { case "user_updated": case "sequence_updated": return details.split(", ").map(changeLabel).join(", "); + case "schedule_run": { + const [name, outcome] = splitLast(details); + return outcome === undefined ? details : `${name} · ${outcomeLabel(outcome)}`; + } + case "schedule_created": + case "schedule_updated": + case "schedule_deleted": + case "schedule_reset": { + // "name · action · recurrence[ · off]": the action in words, the name as typed (system schedules: as stored). + const [name, action, ...rest] = details.split(" · "); + return action === undefined ? details : [name, scheduleAction(action), ...rest.map((r) => r === "off" ? t("Admin.Schedules.Off") : r)].join(" · "); + } default: return details; } diff --git a/src/Chronos.Server/Admin/web/pages/jobs.js b/src/Chronos.Server/Admin/web/pages/jobs.js index b799ab62..183e642a 100644 --- a/src/Chronos.Server/Admin/web/pages/jobs.js +++ b/src/Chronos.Server/Admin/web/pages/jobs.js @@ -1,18 +1,60 @@ -// Jobs (BRIEF §14.8): queue and history with cancel/pause/resume/retry/priority, log tails, render nodes. +// Jobs (BRIEF §14.8): two tabs in the header. Queue: queue and history with cancel/pause/resume/retry/priority, log tails, +// render nodes; #/jobs?job= opens that job's log. Scheduled (#/jobs?tab=schedules, owner review 2, R10): the server's +// schedules, its system ones included (schedules.js). import { t, plural, applyStrings } from "../i18n.js"; -import { escapeHtml, attr, formatTime, formatDateTime, toast, errorText, confirmDialog, emptyState, redraw, fitColumns } from "../ui.js"; +import { escapeHtml, attr, formatTime, formatDateTime, toast, errorText, confirmDialog, emptyState, redraw, fitColumns, routeParams } from "../ui.js"; import { kindLabel, nodeLabel, progressCell, stateCell, stateLabel, encoders, logText } from "../jobs.js"; +import { renderSchedules } from "../schedules.js"; +const TABS = ["queue", "schedules"]; const FILTERS = ["all", "running", "queued", "paused", "failed", "done", "cancelled"]; const PRIORITIES = ["background", "normal", "user"]; -export async function render(root, { api, setMeta, onEvent }) { +export async function render(root, context) { + const { actions, onEvent } = context; + let tab = TABS.includes(routeParams().get("tab")) ? routeParams().get("tab") : "queue"; + // The open tab's event handler: the page subscribes once, a tab that was left hears nothing more. + let handler = null; + onEvent((e) => handler?.(e)); + + actions.innerHTML = `
${TABS.map((name) => + ``).join("")}
+ `; + applyStrings(actions); + const tabActions = actions.querySelector("#tab-actions"); + actions.querySelectorAll("[data-tab]").forEach((b) => b.addEventListener("click", () => { + if (b.dataset.tab === tab) return; + tab = b.dataset.tab; + actions.querySelectorAll("[data-tab]").forEach((x) => x.setAttribute("aria-pressed", String(x === b))); + history.replaceState(null, "", tab === "queue" ? "#/jobs" : "#/jobs?tab=schedules"); + show(); + })); + + async function show() { + handler = null; + tabActions.innerHTML = ""; + // Each tab draws into a body of its own, so a late answer of the tab that was left never touches the new one. + root.innerHTML = `
`; + const body = root.firstElementChild; + const scoped = { ...context, actions: tabActions, onEvent: (fn) => { handler = fn; } }; + if (tab === "queue") await renderQueue(body, scoped, routeParams().get("job")); + else await renderSchedules(body, scoped, routeParams().get("schedule")); + } + + await show(); +} + +/** The Queue tab; (a job id from a schedule's runs) is shown first with its log open. */ +async function renderQueue(root, { api, setMeta, onEvent }, focusJob) { let filter = "all"; let jobs = []; let nodes = []; let running = 0; let cursor = null; - const expanded = new Set(); + // The job a schedule's run links to stays first while the list does not hold it; it gets the focus once. + const pinId = focusJob; + let pinned = null; + const expanded = new Set(pinId ? [pinId] : []); let timer = null; root.innerHTML = ` @@ -47,6 +89,7 @@ export async function render(root, { api, setMeta, onEvent }) { } async function load(more = false) { + if (!root.isConnected) return; try { const state = filter === "all" ? "" : `&state=${filter}`; const [page, list, active] = await Promise.all([ @@ -59,20 +102,29 @@ export async function render(root, { api, setMeta, onEvent }) { cursor = page.nextCursor; nodes = list; running = active.items.length; + pinned = pinId && !jobs.some((j) => j.id === pinId) ? await api.get(`/api/v1/jobs/${pinId}`).catch(() => null) : null; } catch (err) { toast(errorText(err), true); return; } + if (!root.isConnected) return; setMeta(`${plural("Admin.Jobs.RunningCount", running)} · ${plural("Admin.Jobs.NodesOnline", nodes.filter((n) => n.state !== "offline").length)}`); draw(); + if (focusJob) { + root.querySelector(`[data-toggle="${CSS.escape(focusJob)}"]`)?.focus(); + root.querySelector(`[data-key="${CSS.escape(focusJob)}"]`)?.scrollIntoView({ block: "center" }); + focusJob = null; + } } function draw() { const host = root.querySelector("#rows"); + const shown = pinned ? [pinned, ...jobs] : jobs; redraw(host, () => { - host.innerHTML = jobs.map((j) => ` + host.innerHTML = shown.map((j) => `
- + ${j.scheduleId + ? `` : ""} ${escapeHtml(j.targetLabel ?? "")} ${escapeHtml(nodeLabel(j, nodes))} ${progressCell(j)} @@ -175,7 +227,7 @@ export async function render(root, { api, setMeta, onEvent }) { onEvent((e) => { if (e.type === "jobProgress") { - const job = jobs.find((j) => j.id === e.jobId); + const job = jobs.find((j) => j.id === e.jobId) ?? (pinned?.id === e.jobId ? pinned : null); if (job) { job.progressDone = e.done; job.progressTotal = e.total; diff --git a/src/Chronos.Server/Admin/web/pages/settings.js b/src/Chronos.Server/Admin/web/pages/settings.js index 666ba1db..2520d6b5 100644 --- a/src/Chronos.Server/Admin/web/pages/settings.js +++ b/src/Chronos.Server/Admin/web/pages/settings.js @@ -1,8 +1,10 @@ // Settings (BRIEF §14.8): server name, ports, TLS, discovery, jobs, limits, language, retention, logs. Values fixed by -// environment variables are read-only here; ports, TLS, chunk size and job history apply at the next restart. Jobs run one -// at a time (owner review 1): the parallelism (photos at once) and the priority queue apply at once, as do the log levels, -// retention, size limits and rotation (owner review 2, R11). About (version, API, database, uptime) is the last group, -// read-only (owner review 2); #/about opens here on it. +// environment variables are read-only here; ports, TLS and chunk size apply at the next restart. How long job history is +// kept is a parameter of the Job history clean-up schedule (Jobs › Scheduled, owner review 2, R10); the audit retention +// saved here is the Audit log clean-up schedule's age limit. Jobs run one at a time (owner review 1): the parallelism +// (photos at once) and the priority queue apply at once, as do the log levels, retention, size limits and rotation +// (owner review 2, R11). About (version, API, database, uptime) is the last group, read-only (owner review 2); #/about +// opens here on it. import { t, applyStrings, languages } from "../i18n.js"; import { escapeHtml, attr, toast, errorText, nativeName, fingerprint, formatDuration, markInvalid, clearInvalid, invalidText, escapeReverts, routeParams, PROXY_WARNING } from "../ui.js"; import { kindLabel } from "../jobs.js"; @@ -94,7 +96,6 @@ export async function render(root, { api, info, setMeta, actions }) { ${number("chunkSizeMib", settings.chunkSizeBytes / MIB, 'min="0.0625" max="64" step="0.0625"')} ${number("tokenLifetimeDays", settings.tokenLifetimeDays, 'min="1" max="365"')} ${number("uploadRetentionHours", settings.uploadRetentionHours, 'min="1" max="8760"')} - ${number("jobHistoryDays", settings.jobHistoryDays, 'min="1" max="3650"')}

@@ -104,7 +105,7 @@ export async function render(root, { api, info, setMeta, actions }) { ${number("logMaxFileMb", settings.logs.maxFileMb, 'min="0" max="10240"')} ${number("logMaxTotalMb", settings.logs.maxTotalMb, 'min="0" max="1048576"')} ${choice("logRotation", settings.logs.rotation, ROTATIONS, (r) => `Admin.Settings.Rotation.${cap(r)}`)} - ${number("auditRetentionDays", settings.logs.auditRetentionDays, 'min="0" max="36500"')} + ${number("auditRetentionDays", settings.logs.auditRetentionDays, 'min="0" max="3650"')} ${number("diagnosticsLogMb", settings.logs.diagnosticsLogMb, 'min="1" max="1024"')}
@@ -180,7 +181,6 @@ export async function render(root, { api, info, setMeta, actions }) { chunkSizeBytes: Math.round(Number(data.get("chunkSizeMib")) * MIB), tokenLifetimeDays: Number(data.get("tokenLifetimeDays")), uploadRetentionHours: Number(data.get("uploadRetentionHours")), - jobHistoryDays: Number(data.get("jobHistoryDays")), logs: { fileLevel: String(value("logLevel", settings.logs.fileLevel)), consoleLevel: String(value("consoleLogLevel", settings.logs.consoleLevel)), diff --git a/src/Chronos.Server/Admin/web/schedules.js b/src/Chronos.Server/Admin/web/schedules.js new file mode 100644 index 00000000..9baf494f --- /dev/null +++ b/src/Chronos.Server/Admin/web/schedules.js @@ -0,0 +1,534 @@ +// Scheduled jobs (owner review 2, R10): the Scheduled tab of the Jobs page (#/jobs?tab=schedules). Every schedule of the +// server, its system schedules first (the timers it runs, shown so nothing runs out of sight), with when it runs in the +// server's time zone, its next run, its last result and a switch; Run now, Edit, Delete (user schedules) and Reset +// (system schedules). A schedule's name opens its last runs, each linking to its job on the Queue tab. A side panel +// creates and edits schedules: the action (those the server cannot run are disabled, their reason in the tooltip), the +// recurrence, the action's parameters, priority, catch-up and the switch. +import { t, plural, has, applyStrings, culture } from "./i18n.js"; +import { escapeHtml, attr, formatNumber, formatTime, formatDateTime, toast, errorText, confirmDialog, emptyState, redraw, focusPlace, restoreFocus, fitColumns, + markInvalid, clearInvalid, invalidText } from "./ui.js"; +import { kindLabel, pascal, stateCell } from "./jobs.js"; + +const KINDS = ["every", "daily", "weekly", "monthly"]; +const UNITS = ["minutes", "hours", "days"]; +/** Day names of the API, Monday first; 1 January 2001 was a Monday. */ +const DAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]; +const PRIORITIES = ["background", "normal", "user"]; +/** The parameters each action reads (ScheduleActions.Normalize), in the order the form shows them. */ +const PARAMETERS = { + scan: ["force", "deep"], verify: ["olderThanDays", "percent"], thumbnails: ["force"], proxies: ["force"], analysis: ["deep"], + maintenance: ["dryRun"], backup: ["keep"], cleanup: ["steps", "olderThanDays"], duplicates: [], orphans: [], +}; +/** What a new schedule of an action starts with (ScheduleActions.Defaults); absent values are false or off. */ +const DEFAULTS = { verify: { olderThanDays: 30, percent: 100 }, backup: { keep: 3 }, cleanup: { steps: ["job-history"], olderThanDays: 90 } }; +/** A parameter's label and tooltip by action, under Admin.Schedules.Param. */ +const PARAM_KEYS = { + "scan.force": "FullScan", "scan.deep": "DeepAfterScan", "thumbnails.force": "MakeAgain", "proxies.force": "MakeAgain", "analysis.deep": "Deep", + "verify.olderThanDays": "UncheckedDays", "verify.percent": "Percent", "maintenance.dryRun": "DryRun", "backup.keep": "Keep", + "cleanup.steps": "Steps", "cleanup.olderThanDays": "OlderDays", +}; +const NUMBERS = { olderThanDays: 'min="0" max="3650"', percent: 'min="1" max="100"', keep: 'min="1" max="100"' }; +/** Settings an environment variable fixes for a system schedule's age limit (ServerScheduleHost.LockedAgeOf). */ +const LOCKED_AGES = { "audit-cleanup": ["AuditRetentionDays", "CHRONOS_AUDIT_RETENTION_DAYS"] }; + +/** A schedule's name: a system schedule's in the panel's language (by its key), a user's as typed. */ +export function scheduleName(schedule) { + const key = schedule.systemKey ? `Admin.Schedules.System.${pascal(schedule.systemKey)}` : null; + return key && has(key) ? t(key) : schedule.name; +} + +export function actionLabel(action) { + const key = `Admin.Schedules.Action.${pascal(action)}`; + return has(key) ? t(key) : action; +} + +/** "Queued", "Skipped: busy", "Failed"… for an outcome code (failed: included). */ +export function outcomeLabel(outcome) { + if (String(outcome).startsWith("failed:")) return t("Admin.Schedules.Outcome.Failed"); + const key = `Admin.Schedules.Outcome.${pascal(outcome ?? "")}`; + return has(key) ? t(key) : String(outcome ?? ""); +} + +/** What an outcome means, as one sentence (a failure with its reason). */ +export function outcomeTip(outcome) { + const text = String(outcome ?? ""); + if (text.startsWith("failed:")) return t("Admin.Schedules.Outcome.Failed.Tip", text.slice("failed:".length)); + const key = `Admin.Schedules.Outcome.${pascal(text)}.Tip`; + return has(key) ? t(key) : text; +} + +/** "Every 10 minutes", "Daily at 03:00", "Mon, Thu at 02:30", "Day 1 of each month at 04:00" in the panel's language. */ +export function recurrenceText(r) { + switch (r?.kind) { + case "every": return UNITS.includes(r.unit) ? plural(`Admin.Schedules.Every.${cap(r.unit)}`, r.every) : `${r.every} ${r.unit}`; + case "daily": return t("Admin.Schedules.DailyAt", timeText(r.time)); + case "weekly": return t("Admin.Schedules.WeeklyAt", dayList(r.days ?? []), timeText(r.time)); + case "monthly": return t("Admin.Schedules.MonthlyAt", formatNumber(r.dayOfMonth), timeText(r.time)); + default: return r?.kind ?? ""; + } +} + +export async function renderSchedules(root, { api, setMeta, actions, onEvent }, focusSchedule) { + let schedules = []; + let available = []; + let steps = []; + let zone = "UTC"; + let locked = []; + let lastJobs = new Map(); + const runs = new Map(); + const expanded = new Set(focusSchedule ? [focusSchedule] : []); + let opener = null; + let timer = null; + + actions.innerHTML = ``; + applyStrings(actions); + actions.querySelector("#new").addEventListener("click", () => openForm(null)); + + root.innerHTML = ` +
+
+
+
+ + +
+
+
+
+ +
`; + applyStrings(root); + const table = root.querySelector(".table"); + const side = root.querySelector("#side"); + side.addEventListener("keydown", (e) => { + if (e.key === "Escape") { + e.preventDefault(); + closeSide(); + } + }); + + async function load() { + if (!root.isConnected) return; + try { + const [list, settings] = await Promise.all([api.get("/api/v1/schedules"), api.get("/api/v1/server/settings").catch(() => null)]); + schedules = list.items; + available = list.actions; + steps = list.steps ?? []; + zone = list.timeZone; + locked = settings?.locked ?? []; + // The state of each schedule's last job, for the Last result column (a job the history no longer has shows the outcome). + const ids = [...new Set(schedules.filter((s) => s.lastJobId && s.lastOutcome === "queued").map((s) => s.lastJobId))]; + const jobs = await Promise.all(ids.map((id) => api.get(`/api/v1/jobs/${id}`).catch(() => null))); + lastJobs = new Map(jobs.filter(Boolean).map((j) => [j.id, j])); + await Promise.all([...expanded].map((id) => loadRuns(id))); + } catch (err) { + toast(errorText(err), true); + return; + } + if (!root.isConnected) return; + setMeta(`${plural("Admin.Schedules.Count", schedules.length)} · ${t("Admin.Schedules.TimeZone", zone)}`); + draw(); + if (focusSchedule) { + root.querySelector(`[data-key="${CSS.escape(focusSchedule)}"]`)?.scrollIntoView({ block: "center" }); + root.querySelector(`[data-toggle="${CSS.escape(focusSchedule)}"]`)?.focus(); + focusSchedule = null; + } + } + + /** The first page of a schedule's runs, or the next one with more. */ + async function loadRuns(id, more = false) { + const known = runs.get(id); + const cursor = more && known?.cursor ? `&cursor=${encodeURIComponent(known.cursor)}` : ""; + const page = await api.get(`/api/v1/schedules/${id}/runs?limit=10${cursor}`); + runs.set(id, { items: more && known ? known.items.concat(page.items) : page.items, cursor: page.nextCursor }); + } + + function draw() { + const host = root.querySelector("#rows"); + redraw(host, () => { + host.innerHTML = schedules.map(rowHtml).join("") || `
${emptyState("Admin.Schedules.Empty", + ``)}
`; + applyStrings(host); + }); + host.querySelectorAll("[data-toggle]").forEach((b) => b.addEventListener("click", () => toggle(b.dataset.toggle))); + host.querySelectorAll("[data-act]").forEach((b) => b.addEventListener("click", () => act(b.dataset.act, find(b.closest("[data-key]").dataset.key)))); + host.querySelectorAll("[data-enable]").forEach((box) => box.addEventListener("change", () => setEnabled(find(box.dataset.enable), box))); + host.querySelectorAll("[data-more-runs]").forEach((b) => b.addEventListener("click", () => moreRuns(b.dataset.moreRuns))); + host.querySelectorAll("[data-run-first]").forEach((b) => b.addEventListener("click", () => act("run", find(b.dataset.runFirst)))); + host.querySelector("#empty-new")?.addEventListener("click", () => openForm(null)); + fitColumns(table); + } + + function find(id) { + return schedules.find((s) => s.id === id); + } + + function rowHtml(s) { + const name = scheduleName(s); + const button = (act, key, extra = "") => ``; + const buttons = button("run", "Run") + button("edit", "Edit") + (s.systemKey ? button("reset", "Reset") : button("delete", "Delete", " destructive")); + const when = recurrenceText(s.recurrence); + return ` +
+ ${s.systemKey + ? `` : ""} + ${escapeHtml(actionLabel(s.action))} + ${escapeHtml(when)} + ${escapeHtml(s.enabled ? zonedTime(s.nextRun, zone) : t("Admin.Schedules.Off"))} + ${lastResult(s)} + + ${buttons} +
+ ${expanded.has(s.id) ? `
${runsHtml(s)}
` : ""}`; + } + + /** The last result: the last job's state when the run queued one, else what the run did; when, in the tooltip's words. */ + function lastResult(s) { + if (!s.lastRun) return ``; + const when = ` · ${escapeHtml(formatTime(s.lastRun))}`; + const tip = `${outcomeTip(s.lastOutcome)} · ${formatDateTime(s.lastRun)}`; + const job = s.lastOutcome === "queued" ? lastJobs.get(s.lastJobId) : null; + if (job) return `${stateCell(job.state)}${when}`; + const failed = String(s.lastOutcome).startsWith("failed:"); + return `${escapeHtml(outcomeLabel(s.lastOutcome))}${when}`; + } + + function runsHtml(s) { + const page = runs.get(s.id); + if (!page) return ""; + if (page.items.length === 0) { + return emptyState("Admin.Schedules.NoRuns", ``); + } + return `
${page.items.map((j) => ` +
${escapeHtml(kindLabel(j.kind))}${stateCell(j.state)} + ${escapeHtml(formatDateTime(j.created))} +
`).join("")} + ${page.cursor ? `` : ""}
`; + } + + async function toggle(id) { + if (expanded.delete(id)) { + draw(); + return; + } + expanded.add(id); + try { + await loadRuns(id); + } catch (err) { + toast(errorText(err), true); + } + draw(); + } + + async function moreRuns(id) { + try { + await loadRuns(id, true); + } catch (err) { + toast(errorText(err), true); + return; + } + draw(); + } + + async function act(action, schedule) { + if (!schedule) return; + try { + if (action === "edit") return openForm(schedule); + if (action === "run") { + const run = await api.post(`/api/v1/schedules/${schedule.id}/run`); + toast(outcomeTip(run.outcome), String(run.outcome).startsWith("failed:")); + runs.delete(schedule.id); + } else if (action === "delete") { + const confirmed = await confirmDialog({ + title: t("Admin.Schedules.DeleteTitle", scheduleName(schedule)), + confirm: t("Admin.Schedules.Delete"), + confirmTip: t("Admin.Schedules.Delete.Tip"), + cancel: t("Admin.Common.Keep"), + cancelTip: t("Admin.Common.Keep.Tip"), + }); + if (!confirmed) return; + await api.del(`/api/v1/schedules/${schedule.id}`); + expanded.delete(schedule.id); + } else if (action === "reset") { + const confirmed = await confirmDialog({ + title: t("Admin.Schedules.ResetTitle", scheduleName(schedule)), + confirm: t("Admin.Schedules.Reset"), + confirmTip: t("Admin.Schedules.Reset.Tip"), + cancel: t("Admin.Common.Keep"), + cancelTip: t("Admin.Common.Keep.Tip"), + }); + if (!confirmed) return; + await api.post(`/api/v1/schedules/${schedule.id}/reset`); + } + await load(); + } catch (err) { + toast(errorText(err), true); + } + } + + async function setEnabled(schedule, box) { + try { + await api.put(`/api/v1/schedules/${schedule.id}`, { enabled: box.checked }); + await load(); + } catch (err) { + box.checked = !box.checked; + toast(errorText(err), true); + } + } + + /** Shows the side panel, remembering which control opened it so closing returns the keyboard there. */ + function openSide(html) { + if (side.hidden) { + const scope = actions.contains(document.activeElement) ? actions : root; + opener = { scope, place: focusPlace(scope) }; + } + side.hidden = false; + side.innerHTML = html; + applyStrings(side); + fitColumns(table); + side.querySelector("#close").addEventListener("click", closeSide); + } + + function closeSide() { + side.hidden = true; + side.innerHTML = ""; + fitColumns(table); + if (opener) restoreFocus(opener.scope, opener.place); + opener = null; + } + + function openForm(schedule) { + const editing = schedule !== null; + const system = editing && Boolean(schedule.systemKey); + const first = available.find((a) => a.available)?.name ?? "scan"; + const draft = { recurrence: { every: 1, unit: "hours", time: "03:00", days: ["mon"], dayOfMonth: 1, ...(schedule?.recurrence ?? { kind: "daily" }) } }; + const fixed = `disabled title="${attr(t("Admin.Schedules.Fixed.Tip"))}"`; + const actionOptions = (editing && !available.some((a) => a.name === schedule.action) ? [{ name: schedule.action, available: false }] : available).map((a) => + ``).join(""); + openSide(` +
+

+ + + +
+
+ + + +
+ + +
+
`); + const form = side.querySelector("form"); + const values = (action) => action === schedule?.action ? schedule.parameters : (DEFAULTS[action] ?? {}); + drawRecurrence(form, draft.recurrence); + drawParameters(form, schedule?.action ?? first, values(schedule?.action ?? first), schedule?.systemKey); + form.elements.kind.addEventListener("change", () => { + // The fields drawn are still those of the kind chosen before. + draft.recurrence = { ...draft.recurrence, ...shownFields(form, draft.recurrence.kind), kind: form.elements.kind.value }; + drawRecurrence(form, draft.recurrence); + }); + form.elements.action.addEventListener("change", () => drawParameters(form, form.elements.action.value, values(form.elements.action.value), schedule?.systemKey)); + form.addEventListener("submit", async (e) => { + e.preventDefault(); + form.querySelectorAll("[aria-invalid]").forEach(clearInvalid); + const action = form.elements.action.value; + const body = { + recurrence: recurrenceOf(form), + parameters: parametersOf(form, action), + priority: form.elements.priority.value, + catchUp: form.elements.catchUp.checked, + enabled: form.elements.enabled.checked, + }; + if (!system) Object.assign(body, { name: form.elements.name.value.trim(), action }); + try { + if (editing) await api.put(`/api/v1/schedules/${schedule.id}`, body); + else await api.post("/api/v1/schedules", body); + closeSide(); + toast(t("Admin.Common.Saved")); + await load(); + } catch (err) { + fieldError(form, err); + } + }); + (form.querySelector("input:not([disabled]), select:not([disabled])"))?.focus(); + } + + /** The fields of the recurrence's kind, filled from (values of the other kinds are kept for a switch back). */ + function drawRecurrence(form, r) { + const host = form.querySelector("#recurrence"); + const time = ``; + switch (r.kind) { + case "every": + host.innerHTML = ``; + break; + case "weekly": + host.innerHTML = `
${DAYS.map((d) => ``).join("")}
${time}`; + break; + case "monthly": + host.innerHTML = `${time}`; + break; + default: + host.innerHTML = time; + } + applyStrings(host); + } + + /** The parameters reads, filled from . */ + function drawParameters(form, action, p, systemKey) { + const host = form.querySelector("#parameters"); + const lockedAge = LOCKED_AGES[systemKey]; + const ageLocked = lockedAge && locked.some((l) => l.toLowerCase() === lockedAge[0].toLowerCase()); + host.innerHTML = (PARAMETERS[action] ?? []).map((name) => { + const key = `Admin.Schedules.Param.${PARAM_KEYS[`${action}.${name}`]}`; + if (name === "steps") { + return `
${steps.map((step) => ``).join("")}
`; + } + if (name in NUMBERS) { + const lock = name === "olderThanDays" && ageLocked ? `disabled title="${attr(t("Admin.Settings.Locked.Tip", lockedAge[1]))}"` : `data-i18n-title="${key}.Tip"`; + return ``; + } + return ``; + }).join(""); + applyStrings(host); + } + + /** An API failure on the side form: the field it concerns gets the error border, the message and the focus; a toast announces it. */ + function fieldError(form, err) { + const field = fieldOf(form, err.code === "setting_locked" ? "parameters.olderThanDays" : err.code === "invalid_schedule" ? err.details : null); + const message = field && err.code === "invalid_schedule" ? invalidText(field) : errorText(err); + if (field) { + markInvalid(field, message); + field.focus(); + } + toast(message, true); + } + + setMeta(""); + onEvent((e) => { + // A schedule's run queues jobs; their states change the Last result column. + if (e.type === "jobState") { + clearTimeout(timer); + timer = setTimeout(load, 800); + } + }); + await load(); +} + +/** The recurrence the form describes (RecurrenceDto). */ +function recurrenceOf(form) { + const kind = form.elements.kind.value; + return { kind, ...shownFields(form, kind) }; +} + +/** The values of the recurrence fields the form shows for . */ +function shownFields(form, kind) { + const el = form.elements; + switch (kind) { + case "every": return { every: Number(el.every.value), unit: el.unit.value }; + case "weekly": return { time: el.time.value, days: DAYS.filter((d) => el[`day-${d}`].checked) }; + case "monthly": return { time: el.time.value, dayOfMonth: Number(el.dayOfMonth.value) }; + default: return { time: el.time.value }; + } +} + +/** The parameters of the form holds (disabled fields included: an age limit an environment variable fixes). */ +function parametersOf(form, action) { + const parameters = {}; + for (const name of PARAMETERS[action] ?? []) { + if (name === "steps") parameters.steps = [...form.querySelectorAll('input[name^="step-"]')].filter((b) => b.checked).map((b) => b.value); + else if (name in NUMBERS) parameters[name] = Number(form.elements[name].value); + else parameters[name] = form.elements[name].checked; + } + return parameters; +} + +/** The form field an invalid API field (recurrence, parameters.percent…) belongs to. */ +function fieldOf(form, apiField) { + if (!apiField) return null; + const el = form.elements; + if (apiField === "recurrence") { + const kind = el.kind.value; + if (kind === "every") return el.every; + if (kind === "weekly" && !DAYS.some((d) => el[`day-${d}`].checked)) return el["day-mon"]; + if (kind === "monthly" && !(Number(el.dayOfMonth.value) >= 1 && Number(el.dayOfMonth.value) <= 28)) return el.dayOfMonth; + return el.time; + } + if (apiField === "parameters.steps") return form.querySelector('input[name^="step-"]'); + const name = apiField.startsWith("parameters.") ? apiField.slice("parameters.".length) : apiField; + return el[name] ?? null; +} + +function actionTip(action) { + const key = `Admin.Schedules.Action.${pascal(action)}.Tip`; + return has(key) ? t(key) : action; +} + +/** Why the server cannot run an action (ScheduleUnavailable codes; unknown codes read "not available here"). */ +function reasonTip(reason) { + const key = `Admin.Schedules.Reason.${pascal(reason ?? "")}.Tip`; + return has(key) ? t(key) : t("Admin.Schedules.Reason.Unknown.Tip"); +} + +function stepLabel(step) { + const key = `Admin.Schedules.Step.${pascal(step)}`; + return has(key) ? t(key) : step; +} + +function stepTip(step) { + const key = `Admin.Schedules.Step.${pascal(step)}.Tip`; + return has(key) ? t(key) : step; +} + +/** An instant in the server's time zone (schedule times are its wall-clock times); in the browser's when the zone is unknown here. */ +function zonedTime(iso, zone) { + if (!iso) return "—"; + const options = { dateStyle: "short", timeStyle: "short" }; + try { + return new Intl.DateTimeFormat(culture(), { ...options, timeZone: zone }).format(new Date(iso)); + } catch { + return new Intl.DateTimeFormat(culture(), options).format(new Date(iso)); + } +} + +/** "03:00" as the panel's language writes a time of day. */ +function timeText(hhmm) { + const [h, m] = String(hhmm ?? "").split(":").map(Number); + if (!Number.isFinite(h) || !Number.isFinite(m)) return String(hhmm ?? ""); + return new Intl.DateTimeFormat(culture(), { timeStyle: "short", timeZone: "UTC" }).format(Date.UTC(2001, 0, 1, h, m)); +} + +function dayName(day, style = "short") { + return new Intl.DateTimeFormat(culture(), { weekday: style, timeZone: "UTC" }).format(Date.UTC(2001, 0, 1 + DAYS.indexOf(day))); +} + +function dayList(days) { + const names = DAYS.filter((d) => days.includes(d)).map((d) => dayName(d)); + try { + return new Intl.ListFormat(culture(), { style: "short", type: "conjunction" }).format(names); + } catch { + return names.join(", "); + } +} + +function cap(s) { + return s.charAt(0).toUpperCase() + s.slice(1); +} diff --git a/src/Chronos.Server/Api/ScheduleEndpoints.cs b/src/Chronos.Server/Api/ScheduleEndpoints.cs new file mode 100644 index 00000000..a82a8dee --- /dev/null +++ b/src/Chronos.Server/Api/ScheduleEndpoints.cs @@ -0,0 +1,116 @@ +using Chronos.Core.Model; +using Chronos.Data; +using Chronos.Data.Scheduling; +using Chronos.Protocol; +using Chronos.Server.Jobs; +using Chronos.Server.Security; + +namespace Chronos.Server.Api; + +/// +/// /api/v1/schedules (owner review 2, R10; ManageArchive): the server's scheduled jobs, its system schedules +/// included, with the actions it can run and its time zone; create, edit (PUT or PATCH, the fields given), +/// delete (409 schedule_system for a system schedule), run now (409 schedule_pending while its last job is +/// queued, running or paused), reset a system schedule (409 schedule_no_defaults otherwise) and the jobs a schedule +/// queued, newest first. An invalid field is 400 invalid_schedule with its name as details (name, +/// recurrence, parameters.percent…); an age limit an environment variable fixes is 409 setting_locked. +/// Every change is audited. +/// +public static class ScheduleEndpoints +{ + public static void Map(RouteGroupBuilder api) + { + var schedules = api.MapGroup("/schedules").Requires(Permissions.ManageArchive); + schedules.MapGet("", async (HttpContext context, SchedulerHost host) => + Results.Json(await host.Scheduler.ListAsync(context.RequestAborted), ProtocolJson.Default.SchedulesDto)); + schedules.MapPost("", CreateAsync); + schedules.MapGet("/{id:guid}", async (HttpContext context, Guid id, SchedulerHost host) => + await host.Scheduler.GetAsync(id, context.RequestAborted) is { } schedule + ? Results.Json(schedule, ProtocolJson.Default.ScheduleDto) + : ApiErrors.NotFound(context, "schedule")); + schedules.MapPut("/{id:guid}", UpdateAsync); + schedules.MapPatch("/{id:guid}", UpdateAsync); + schedules.MapDelete("/{id:guid}", DeleteAsync); + schedules.MapPost("/{id:guid}/run", RunAsync); + schedules.MapPost("/{id:guid}/reset", ResetAsync); + schedules.MapGet("/{id:guid}/runs", RunsAsync); + } + + private static async Task CreateAsync(HttpContext context, Caller caller, CreateScheduleRequest request, SchedulerHost host, AuditLog audit) + { + var result = await host.Scheduler.CreateAsync(request, caller.Id, context.RequestAborted); + if (result.Problem is { } problem) return ApiErrors.BadRequest(context, "invalid_schedule", problem, problem); + var schedule = result.Schedule!; + await audit.WriteAsync(caller, context, "schedule_created", "schedule", schedule.Id.ToString(), Describe(schedule)); + return Results.Json(schedule, ProtocolJson.Default.ScheduleDto, statusCode: StatusCodes.Status201Created); + } + + private static async Task UpdateAsync(HttpContext context, Caller caller, Guid id, UpdateScheduleRequest request, SchedulerHost host, AuditLog audit) + { + var ct = context.RequestAborted; + if (await host.Scheduler.GetAsync(id, ct) is not { } current) return ApiErrors.NotFound(context, "schedule"); + // Parameters are replaced as a whole: a missing age limit would fall back to the action's default. + if (host.Host.LockedAgeOf(current.SystemKey) is { } locked && request.Parameters is { } parameters + && ScheduleActions.Normalize(current.Action, parameters).OlderThanDays != locked.Days) + return ApiErrors.Conflict(context, "setting_locked", locked.Setting); + var result = await host.Scheduler.UpdateAsync(id, request, ct); + if (result.NotFound) return ApiErrors.NotFound(context, "schedule"); + if (result.Problem is { } problem) return ApiErrors.BadRequest(context, "invalid_schedule", problem, problem); + var schedule = result.Schedule!; + await audit.WriteAsync(caller, context, "schedule_updated", "schedule", id.ToString(), Describe(schedule)); + return Results.Json(schedule, ProtocolJson.Default.ScheduleDto); + } + + private static async Task DeleteAsync(HttpContext context, Caller caller, Guid id, SchedulerHost host, AuditLog audit) + { + var ct = context.RequestAborted; + var current = await host.Scheduler.GetAsync(id, ct); + switch (await host.Scheduler.DeleteAsync(id, ct)) + { + case ScheduleDeleteOutcome.System: + return ApiErrors.Conflict(context, "schedule_system"); + case ScheduleDeleteOutcome.NotFound: + return ApiErrors.NotFound(context, "schedule"); + } + await audit.WriteAsync(caller, context, "schedule_deleted", "schedule", id.ToString(), current is null ? null : Describe(current)); + return Results.NoContent(); + } + + /// Runs the schedule now, as its next run would (also a disabled one), unless its last job has not ended. + private static async Task RunAsync(HttpContext context, Caller caller, Guid id, SchedulerHost host, ChronosDatabase db, AuditLog audit) + { + var ct = context.RequestAborted; + if (await host.Scheduler.GetAsync(id, ct) is not { } schedule) return ApiErrors.NotFound(context, "schedule"); + if (schedule.LastJobId is { } last && await db.Jobs.GetAsync(last, ct) is { State: JobState.Queued or JobState.Running or JobState.Paused }) + return ApiErrors.Conflict(context, "schedule_pending", last.ToString()); + if (await host.Scheduler.RunNowAsync(id, caller.Id, ct) is not { } run) return ApiErrors.NotFound(context, "schedule"); + await audit.WriteAsync(caller, context, "schedule_run", "schedule", id.ToString(), $"{run.Schedule.Name} · {run.Outcome}"); + return Results.Json(run, ProtocolJson.Default.ScheduleRunDto); + } + + private static async Task ResetAsync(HttpContext context, Caller caller, Guid id, SchedulerHost host, AuditLog audit) + { + var result = await host.Scheduler.ResetAsync(id, context.RequestAborted); + if (result.NotFound) return ApiErrors.NotFound(context, "schedule"); + if (result.Problem is not null) return ApiErrors.Conflict(context, "schedule_no_defaults"); + var schedule = result.Schedule!; + await audit.WriteAsync(caller, context, "schedule_reset", "schedule", id.ToString(), Describe(schedule)); + return Results.Json(schedule, ProtocolJson.Default.ScheduleDto); + } + + /// The jobs the schedule queued, newest first; cursor continues a page. + private static async Task RunsAsync(HttpContext context, Guid id, SchedulerHost host, ChronosDatabase db, string? cursor, int? limit) + { + var ct = context.RequestAborted; + if (await host.Scheduler.GetAsync(id, ct) is null) return ApiErrors.NotFound(context, "schedule"); + var page = await db.Jobs.PageByScheduleAsync(id, limit ?? 20, string.IsNullOrEmpty(cursor) ? null : cursor, ct); + return Results.Json(new Page([.. page.Items.Select(Dto.Job)], page.NextCursor, null), ProtocolJson.Default.PageJobDto); + } + + /// The audit details of a schedule: its name, action and recurrence (Archive scan · scan · every:10m), and "off" while disabled. + private static string Describe(ScheduleDto schedule) + { + var recurrence = ScheduleMapping.FromDto(schedule.Recurrence)?.Format() ?? schedule.Recurrence.Kind; + return $"{schedule.Name} · {schedule.Action} · {recurrence}{(schedule.Enabled ? string.Empty : " · off")}"; + } +} diff --git a/src/Chronos.Server/Configuration/ServerOptions.cs b/src/Chronos.Server/Configuration/ServerOptions.cs index b393ed80..a2d6f689 100644 --- a/src/Chronos.Server/Configuration/ServerOptions.cs +++ b/src/Chronos.Server/Configuration/ServerOptions.cs @@ -3,6 +3,7 @@ using System.Net; using System.Text.Json; using System.Text.Json.Serialization; using Chronos.Data; +using Chronos.Data.Scheduling; using Chronos.Server.Hosting; using LogFileOptions = Chronos.Core.Diagnostics.LogFileOptions; using LogRotation = Chronos.Core.Diagnostics.LogRotation; @@ -75,7 +76,7 @@ public sealed class ServerOptions ("CHRONOS_LOG_MAX_FILE_MB", nameof(LogMaxFileMb), (o, v) => o.LogMaxFileMb = Int("CHRONOS_LOG_MAX_FILE_MB", v)), ("CHRONOS_LOG_MAX_TOTAL_MB", nameof(LogMaxTotalMb), (o, v) => o.LogMaxTotalMb = Int("CHRONOS_LOG_MAX_TOTAL_MB", v)), ("CHRONOS_LOG_ROTATION", nameof(LogRotation), (o, v) => o.LogRotation = ServerLogging.ParseRotation("CHRONOS_LOG_ROTATION", v)), - ("CHRONOS_AUDIT_RETENTION_DAYS", nameof(AuditRetentionDays), (o, v) => o.AuditRetentionDays = Int("CHRONOS_AUDIT_RETENTION_DAYS", v)), + (AuditRetentionVariable, nameof(AuditRetentionDays), (o, v) => o.AuditRetentionDays = Int(AuditRetentionVariable, v)), ("CHRONOS_DIAGNOSTICS_LOG_MB", nameof(DiagnosticsLogMb), (o, v) => o.DiagnosticsLogMb = Int("CHRONOS_DIAGNOSTICS_LOG_MB", v)), ]; @@ -199,14 +200,31 @@ public sealed class ServerOptions /// One log file per UTC day or per hour. public LogRotation LogRotation { get; set; } = LogRotation.Daily; - /// Days audit entries are kept (the scheduler's housekeeping deletes older ones); 0 = forever. - public int AuditRetentionDays { get; set; } - /// MB kept from the end of each log file in the diagnostics zip. public int DiagnosticsLogMb { get; set; } = (int)(Chronos.Core.Diagnostics.DiagnosticsArchive.DefaultLogTailBytes / LogFileOptions.BytesPerMb); public long MaxUploadBytes { get; set; } = 2L * 1024 * 1024 * 1024; public int ChunkSizeBytes { get; set; } = 8 * 1024 * 1024; + + /// + /// Days of job history the housekeeping system schedule keeps when it is created or reset (owner review 2, R10); + /// afterwards the schedule's own value applies (admin panel › Jobs › Scheduled). + /// public int JobHistoryDays { get; set; } = 90; + + /// The environment variable that fixes . + public const string AuditRetentionVariable = "CHRONOS_AUDIT_RETENTION_DAYS"; + + /// Most days accepts: the most a schedule's age limit takes (ten years). + public const int MaxAuditRetentionDays = ScheduleActions.MaxDays; + + /// + /// Days of audit log the audit-cleanup system schedule keeps (owner review 2, R10, R11); 0, the default, keeps + /// it all. It is that schedule's age limit: saving it in Settings › Logs sets the schedule's parameter, and Reset + /// goes back to it. Set by CHRONOS_AUDIT_RETENTION_DAYS, it is applied to the schedule at every start and cannot + /// be changed in the panel or on the schedule. + /// + public int AuditRetentionDays { get; set; } + public int TokenLifetimeDays { get; set; } = 30; /// Uploads untouched for this long are abandoned: their partial files are deleted. @@ -226,7 +244,7 @@ public sealed class ServerOptions /// Chunk uploads one user may run at the same time; more are answered 429. public int ConcurrentChunksPerUser { get; set; } = 8; - /// Settings fixed by environment variables (names of the properties above). + /// Settings fixed by environment variables (names of the properties above); tests set it directly. [JsonIgnore] public IReadOnlyCollection Locked { get; internal set; } = []; diff --git a/src/Chronos.Server/Configuration/ServerSettingsStore.cs b/src/Chronos.Server/Configuration/ServerSettingsStore.cs index e28ad982..dc809dd4 100644 --- a/src/Chronos.Server/Configuration/ServerSettingsStore.cs +++ b/src/Chronos.Server/Configuration/ServerSettingsStore.cs @@ -14,7 +14,8 @@ namespace Chronos.Server.Configuration; /// The admin panel's view of the configuration (BRIEF §14.8 Settings). Saving writes /data/server.json (only the /// edited keys; secrets and environment values are never written) and applies what can change while running, the /// parallelism and the priority queue included (owner review 1), and the log settings through -/// (owner review 2, R11); ports, TLS, chunk size and job history wait for a restart. +/// (owner review 2, R11); ports, TLS and chunk size wait for a restart. Job history is what the housekeeping system +/// schedule is reset to (owner review 2, R10): the schedule's own value applies. ///
public sealed class ServerSettingsStore(ServerOptions options, ServerLogging logging) { @@ -62,6 +63,7 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log options.MaxUploadBytes = request.MaxUploadBytes; options.TokenLifetimeDays = request.TokenLifetimeDays; options.UploadRetentionHours = request.UploadRetentionHours; + options.JobHistoryDays = request.JobHistoryDays; options.Parallelism = request.Parallelism; options.PriorityQueue = request.PriorityQueue; options.JobPriorities = JobPriorityQueue.Changed(Levels(request.JobPriorities)); @@ -78,7 +80,7 @@ public sealed class ServerSettingsStore(ServerOptions options, ServerLogging log var restart = request.HttpPort != options.HttpPort || request.HttpsPort != options.HttpsPort || !string.Equals(request.TlsMode, options.TlsMode.ToString(), StringComparison.OrdinalIgnoreCase) || request.TlsCert != options.TlsCert || request.TlsKey != options.TlsKey - || request.ChunkSizeBytes != options.ChunkSizeBytes || request.JobHistoryDays != options.JobHistoryDays; + || request.ChunkSizeBytes != options.ChunkSizeBytes; _saved = request with { ServerName = request.ServerName.Trim(), diff --git a/src/Chronos.Server/Hosting/ServerCommandLine.cs b/src/Chronos.Server/Hosting/ServerCommandLine.cs index 701015df..bf1746c1 100644 --- a/src/Chronos.Server/Hosting/ServerCommandLine.cs +++ b/src/Chronos.Server/Hosting/ServerCommandLine.cs @@ -49,7 +49,7 @@ public sealed record ServerCommandLine(ServerCommand Command, IReadOnlyList args) diff --git a/src/Chronos.Server/Hosting/ServerHost.cs b/src/Chronos.Server/Hosting/ServerHost.cs index 9132ee5e..6206d011 100644 --- a/src/Chronos.Server/Hosting/ServerHost.cs +++ b/src/Chronos.Server/Hosting/ServerHost.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core; using Chronos.Core.Diagnostics; using Chronos.Data; using Chronos.Data.Archiving; +using Chronos.Data.Housekeeping; using Chronos.Protocol; using Chronos.Server.Api; using Chronos.Server.Configuration; @@ -144,10 +145,16 @@ public static class ServerHost services.AddSingleton(); services.AddSingleton(); services.AddHostedService(sp => sp.GetRequiredService()); + // After the engine's host: the scheduler queues on its engine, starts after it and stops before it (owner review 2, R10). + services.AddSingleton(); + services.AddSingleton(); + services.AddHostedService(sp => sp.GetRequiredService()); services.AddSingleton(); services.AddHostedService(sp => sp.GetRequiredService()); + // Recovers interrupted commits at start; its sweep is the clean-up step of the upload-cleanup schedule. services.AddSingleton(); services.AddHostedService(sp => sp.GetRequiredService()); + services.AddSingleton(); services.AddSingleton(); services.AddHostedService(sp => sp.GetRequiredService()); } @@ -169,6 +176,7 @@ public static class ServerHost FileEndpoints.Map(api); UploadEndpoints.Map(api); JobEndpoints.Map(api); + ScheduleEndpoints.Map(api); NodeEndpoints.Map(api); ArchiveEndpoints.Map(api); AdminEndpoints.Map(api); diff --git a/src/Chronos.Server/Hosting/ServerLogging.cs b/src/Chronos.Server/Hosting/ServerLogging.cs index 4d3700b9..9f8b220d 100644 --- a/src/Chronos.Server/Hosting/ServerLogging.cs +++ b/src/Chronos.Server/Hosting/ServerLogging.cs @@ -18,12 +18,12 @@ public sealed class ServerLogging public const int MaxRetentionDays = 3650; public const int MaxFileMb = 10 * 1024; public const int MaxTotalMb = 1024 * 1024; - public const int MaxAuditRetentionDays = 36500; + public const int MaxAuditRetentionDays = ServerOptions.MaxAuditRetentionDays; public const int MaxDiagnosticsLogMb = 1024; /// The ranges checks, for the start-up error. public const string Ranges = "log retention 1 to 3650 days, log file 0 to 10240 MB, logs total 0 to 1048576 MB and not below the log file, " - + "audit retention 0 to 36500 days, diagnostics logs 1 to 1024 MB"; + + "audit retention 0 to 3650 days, diagnostics logs 1 to 1024 MB"; /// The levels the settings accept, least severe first; their wire names are lower case (information). public static IReadOnlyList Levels { get; } = diff --git a/src/Chronos.Server/Jobs/SchedulerHost.cs b/src/Chronos.Server/Jobs/SchedulerHost.cs new file mode 100644 index 00000000..8b856938 --- /dev/null +++ b/src/Chronos.Server/Jobs/SchedulerHost.cs @@ -0,0 +1,89 @@ +using Chronos.Data; +using Chronos.Data.Scheduling; +using Chronos.Protocol; + +namespace Chronos.Server.Jobs; + +/// +/// Hosts the server's (owner review 2, R10) on the 's engine with the +/// : registered after the engine's host, so it starts after it and stops before it. At start +/// it seeds the system schedules and settles missed runs (), applies the age limits that +/// environment variables fix (), and runs the archive scan once in the +/// background, as the former polling did, so the photos of an adopted folder are indexed without waiting for its first +/// interval (only while that schedule is enabled). +/// +public sealed class SchedulerHost : IHostedService +{ + private readonly ChronosDatabase _db; + private readonly ILogger _logger; + private readonly CancellationTokenSource _stopping = new(); + private Task _startScan = Task.CompletedTask; + private int _stopped; + + public SchedulerHost(ChronosDatabase db, JobEngineHost jobs, ServerScheduleHost host, TimeProvider time, ILogger logger) + { + ArgumentNullException.ThrowIfNull(jobs); + _db = db; + _logger = logger; + Host = host; + Scheduler = new Scheduler(db, jobs.Engine, new SchedulerOptions { Time = time }); + } + + public Scheduler Scheduler { get; } + + public ServerScheduleHost Host { get; } + + public async Task StartAsync(CancellationToken cancellationToken) + { + var started = Scheduler.Options.Time.GetUtcNow(); + await Scheduler.StartAsync(Host, cancellationToken); + await ApplyLockedAgesAsync(cancellationToken); + var stopping = _stopping.Token; + _startScan = Task.Run(() => ScanAtStartAsync(started, stopping), CancellationToken.None); + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + if (Interlocked.Exchange(ref _stopped, 1) == 1) return; + await _stopping.CancelAsync(); + await _startScan; + await Scheduler.DisposeAsync(); + _stopping.Dispose(); + } + + /// + /// Puts the age limits environment variables fix into their system schedules (also enabling one that has a limit now, + /// or disabling it at 0, which keeps everything); a schedule already holding the value is left as the user set it. + /// + private async Task ApplyLockedAgesAsync(CancellationToken cancellationToken) + { + foreach (var system in Host.SystemSchedules) + { + if (Host.LockedAgeOf(system.SystemKey) is not { } locked) continue; + if (await _db.Schedules.GetBySystemKeyAsync(system.SystemKey, cancellationToken) is not { } row) continue; + var parameters = ScheduleMapping.Parameters(row); + if (parameters.OlderThanDays == locked.Days) continue; + var result = await Scheduler.UpdateAsync(row.Id, new UpdateScheduleRequest(Parameters: parameters with { OlderThanDays = locked.Days }, Enabled: locked.Days > 0), + cancellationToken); + if (result.Problem is { } problem) _logger.LogWarning("{Variable} could not be applied to the {Schedule} schedule ({Problem})", locked.Variable, row.Name, problem); + else _logger.LogInformation("{Variable} sets the {Schedule} schedule to {Days} day(s)", locked.Variable, row.Name, locked.Days); + } + } + + /// The archive scan's run at start, unless the first pass already fired it or it is disabled. + private async Task ScanAtStartAsync(DateTimeOffset started, CancellationToken cancellationToken) + { + try + { + if (await _db.Schedules.GetBySystemKeyAsync(ServerScheduleHost.ArchiveScan, cancellationToken) is not { Enabled: true } scan || scan.LastRun >= started) return; + await Scheduler.RunNowAsync(scan.Id, null, cancellationToken); + } + catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) + { + } + catch (Exception ex) + { + _logger.LogWarning(ex, "The archive scan at start could not be queued; its schedule queues the next one"); + } + } +} diff --git a/src/Chronos.Server/Jobs/ServerScheduleHost.cs b/src/Chronos.Server/Jobs/ServerScheduleHost.cs new file mode 100644 index 00000000..a0e0430b --- /dev/null +++ b/src/Chronos.Server/Jobs/ServerScheduleHost.cs @@ -0,0 +1,139 @@ +using Chronos.Core.Archiving; +using Chronos.Core.Model; +using Chronos.Data; +using Chronos.Data.Archiving; +using Chronos.Data.Scheduling; +using Chronos.Protocol; +using Chronos.Server.Configuration; +using Chronos.Server.Storage; + +namespace Chronos.Server.Jobs; + +/// An age limit an environment variable fixes for a system schedule: the setting it comes from, the variable and the days. +public sealed record LockedAge(string Setting, string Variable, int Days); + +/// +/// What the server tells its (owner review 2, R10): the container's time zone (TZ), the archive it +/// serves with the settings another writer put into archive.json (refreshed at every run, as the former polling did), the +/// server's own clean-up steps, and its system schedules, which stand for every timer it ran out of sight before: the +/// archive scan every 10 minutes (no catch-up), the uploads sweep every 30 minutes, the nightly copy of an SQLite index, +/// the job history and the audit log retentions. They are seeded from once (the user's edits +/// stay) and reset to the options as they are then. +/// +public sealed class ServerScheduleHost : IScheduleHost +{ + public const string ArchiveScan = "archive-scan"; + public const string UploadCleanup = "upload-cleanup"; + public const string IndexBackup = "index-backup"; + public const string Housekeeping = "housekeeping"; + public const string AuditCleanup = "audit-cleanup"; + + /// Minutes between two archive scans (the desktop's rhythm, as the polling had). + public const int ScanMinutes = 10; + + /// Minutes between two sweeps of abandoned uploads (as the upload maintenance had). + public const int UploadSweepMinutes = 30; + + private readonly ChronosDatabase _db; + private readonly ServerOptions _options; + private readonly ServerArchive _archive; + private readonly ArchiveService? _archives; + private readonly ILogger _logger; + + public ServerScheduleHost(ChronosDatabase db, ServerOptions options, ServerArchive archive, IServiceProvider services, ILogger logger) + { + ArgumentNullException.ThrowIfNull(services); + _db = db; + _options = options; + _archive = archive; + _logger = logger; + // Without the archive module (tests with a fake ingest) nothing refreshes archive.json and no clean-up step exists. + _archives = services.GetService(); + CleanupSteps = _archives is null ? [] : [.. _archives.CleanupSteps.Select(s => s.Name)]; + TimeZone = ResolveTimeZone(Environment.GetEnvironmentVariable("TZ"), logger); + } + + public TimeZoneInfo TimeZone { get; } + + public IReadOnlyList CleanupSteps { get; } + + /// Built from the options as they are now, so a reset follows a changed . + public IReadOnlyList SystemSchedules + { + get + { + var nightly = (Backup: new TimeOnly(3, 0), History: new TimeOnly(4, 0), Audit: new TimeOnly(4, 30)); + var list = new List + { + // A missed scan is not caught up: the next one comes within minutes and SchedulerHost scans once at start. + new(ArchiveScan, "Archive scan", ScheduleActions.Scan, ScheduleRecurrence.Interval(ScanMinutes, RecurrenceUnit.Minutes), CatchUp: false), + new(UploadCleanup, "Upload clean-up", ScheduleActions.Cleanup, ScheduleRecurrence.Interval(UploadSweepMinutes, RecurrenceUnit.Minutes), + new ScheduleParametersDto(OlderThanDays: UploadMaintenance.FinishedRetentionDays, Steps: [UploadCleanupStep.StepName])), + }; + // PostgreSQL is backed up with its own tools (BRIEF §6.2): no schedule that could never run. + if (DatabaseBackups.Unavailable(_db) is null) + { + list.Add(new(IndexBackup, "Index backup", ScheduleActions.Backup, ScheduleRecurrence.DailyAt(nightly.Backup), + new ScheduleParametersDto(Keep: DatabaseBackups.Keep))); + } + list.Add(new(Housekeeping, "Housekeeping", ScheduleActions.Cleanup, ScheduleRecurrence.DailyAt(nightly.History), + new ScheduleParametersDto(OlderThanDays: _options.JobHistoryDays, Steps: [Chronos.Data.Housekeeping.CleanupSteps.JobHistory]))); + var audit = _options.AuditRetentionDays; + list.Add(new(AuditCleanup, "Audit log clean-up", ScheduleActions.Cleanup, ScheduleRecurrence.DailyAt(nightly.Audit), + new ScheduleParametersDto(OlderThanDays: audit, Steps: [Chronos.Data.Housekeeping.CleanupSteps.Audit]), Enabled: audit > 0)); + return list; + } + } + + /// + /// The served archive, after taking the settings another writer sharing it (a desktop) put into its archive.json, as + /// the former polling did before each scan; while it is offline, or the file cannot be read, as the index has it. + /// + public async ValueTask GetArchiveAsync(CancellationToken cancellationToken) + { + var current = _archive.Current; + if (_archives is null || ArchiveService.GetAvailability(current) == ArchiveAvailability.Offline) return current; + try + { + return await _archive.RefreshAsync(_archives, _db, cancellationToken).ConfigureAwait(false); + } + catch (Exception ex) when (ex is not OperationCanceledException) + { + _logger.LogWarning(ex, "The settings in the archive's archive.json could not be read; schedules use those of the index"); + return _archive.Current; + } + } + + /// The server runs every action it has a handler for; the scheduler finds the rest out itself. + public string? Unavailable(string action) => null; + + /// + /// The age limit of the system schedule that an environment variable fixes + /// (CHRONOS_AUDIT_RETENTION_DAYS for ); null when the schedule's own value applies. + /// + public LockedAge? LockedAgeOf(string? systemKey) => + systemKey == AuditCleanup && _options.Locked.Contains(nameof(ServerOptions.AuditRetentionDays)) + ? new LockedAge(nameof(ServerOptions.AuditRetentionDays), ServerOptions.AuditRetentionVariable, _options.AuditRetentionDays) + : null; + + /// + /// The zone of schedule times: the process's local zone (TZ in a container), by its IANA id where the platform maps it + /// (the admin panel formats times with it); UTC, with a warning, when TZ names a zone this system does not know (no + /// tzdata in the image). + /// + public static TimeZoneInfo ResolveTimeZone(string? tz, ILogger logger) + { + ArgumentNullException.ThrowIfNull(logger); + var name = tz?.Trim().TrimStart(':'); + // TZ may also be a path to a zone file, which the runtime reads itself. + if (!string.IsNullOrEmpty(name) && !Path.IsPathRooted(name) && !OperatingSystem.IsWindows() && !TimeZoneInfo.TryFindSystemTimeZoneById(name, out _)) + { + logger.LogWarning("TZ is {Zone}, a time zone this system does not know (is tzdata installed?): schedules run in UTC", name); + return TimeZoneInfo.Utc; + } + var local = TimeZoneInfo.Local; + if (!local.HasIanaId && TimeZoneInfo.TryConvertWindowsIdToIanaId(local.Id, out var iana) && TimeZoneInfo.TryFindSystemTimeZoneById(iana, out var zone)) + return zone; + return local; + } +} diff --git a/src/Chronos.Server/Storage/ArchiveModule.cs b/src/Chronos.Server/Storage/ArchiveModule.cs index 6cb9db96..0f7aaf94 100644 --- a/src/Chronos.Server/Storage/ArchiveModule.cs +++ b/src/Chronos.Server/Storage/ArchiveModule.cs @@ -1,6 +1,7 @@ using Chronos.Core.Imaging.Decoders; using Chronos.Data; using Chronos.Data.Archiving; +using Chronos.Data.Housekeeping; using Chronos.Data.Jobs; using Chronos.Server.Configuration; @@ -8,10 +9,11 @@ namespace Chronos.Server.Storage; /// /// The archive engine behind the server (BRIEF §7, §14.4): ingest of verified uploads, lookup of proxies and -/// thumbnails, its job handlers (scan, rebuild, verify, import, thumbnails, proxies, maintenance) and the periodic -/// incremental scan (); a scan queues thumbnails and proxies of what it indexes, as an upload -/// does. Decoding is managed only (BRIEF §4.2). The daily backup of an SQLite index runs with it -/// (). +/// thumbnails, and its job handlers (scan, rebuild, verify, import, thumbnails, proxies, maintenance, the duplicates and +/// orphans reports, index backups and clean-ups with the server's own steps, the s in DI); a scan +/// queues thumbnails and proxies of what it indexes, as an upload does. Decoding is managed only (BRIEF §4.2). Recurring +/// work (the periodic scan, the nightly backup of an SQLite index, clean-ups) is queued by the server's system schedules +/// (, owner review 2, R10). /// public static class ArchiveModule { @@ -24,14 +26,19 @@ public static class ArchiveModule { var options = sp.GetRequiredService(); // Photos the running job processes at once: the settings' value as it is when each sequence starts (owner review 1). - return new ArchiveService(sp.GetRequiredService(), - new ArchiveServiceOptions { Decoder = DecoderFactory.CreateServer(), Owner = Owner, ImagesAfterScan = true, Parallelism = () => options.Parallelism }); + return new ArchiveService(sp.GetRequiredService(), new ArchiveServiceOptions + { + Decoder = DecoderFactory.CreateServer(), + Owner = Owner, + ImagesAfterScan = true, + Parallelism = () => options.Parallelism, + CleanupSteps = [.. sp.GetServices()], + // Next to the index in the data folder, where the daily backups always went. + BackupDirectory = Path.Combine(options.DataPath, DatabaseBackups.DirectoryName), + }); }); services.AddSingleton(sp => sp.GetRequiredService().Ingest); services.AddSingleton(sp => sp.GetRequiredService()); services.AddSingleton(); - services.AddHostedService(); - services.AddSingleton(); - services.AddHostedService(sp => sp.GetRequiredService()); } } diff --git a/src/Chronos.Server/Storage/ArchivePolling.cs b/src/Chronos.Server/Storage/ArchivePolling.cs deleted file mode 100644 index 16f36176..00000000 --- a/src/Chronos.Server/Storage/ArchivePolling.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Chronos.Core.Archiving; -using Chronos.Core.Model; -using Chronos.Data; -using Chronos.Data.Archiving; -using Chronos.Server.Jobs; - -namespace Chronos.Server.Storage; - -/// -/// Polls the archive (BRIEF §7: by modification time and size, no file-system watchers): an incremental scan at start -/// and every while the archive is online, so photos already in an adopted folder and sequences -/// another writer adds (a desktop sharing the archive, files copied in by hand) are indexed without an administrator's -/// rescan. Settings such a writer changed in archive.json reach the index first, so uploads and the admin panel follow -/// them. A scan or rebuild of the archive that is waiting, running or paused is not queued again. -/// -public sealed class ArchivePolling(ChronosDatabase db, ServerArchive archive, ArchiveService archives, JobEngineHost jobs, TimeProvider time, - ILogger logger) - : BackgroundService -{ - /// The desktop's rhythm (it polls its archive the same way). - public static readonly TimeSpan Interval = TimeSpan.FromMinutes(10); - - private static readonly JobState[] Pending = [JobState.Queued, JobState.Running, JobState.Paused]; - - /// Queues an incremental scan of an online archive unless one is pending; returns it, or null when none was queued. - public async Task PollAsync(CancellationToken cancellationToken) - { - if (!jobs.CanRun(JobKind.Scan)) return null; - var current = archive.Current; - if (ArchiveService.GetAvailability(current) != ArchiveAvailability.Online) return null; - current = await archive.RefreshAsync(archives, db, cancellationToken); - foreach (var kind in new[] { JobKind.Scan, JobKind.Rebuild }) - { - foreach (var state in Pending) - { - if ((await db.Jobs.ListAsync(state, kind, 50, null, cancellationToken)).Items.Any(j => j.TargetIds.Contains(current.Id))) return null; - } - } - var scan = ArchiveJobs.Scan(current); - // Behind what users asked for (BRIEF §14.6). - return await jobs.Engine.EnqueueAsync(scan.Kind, scan.Targets, scan.Label, scan.ParametersJson, JobPriority.Background, - cancellationToken: cancellationToken); - } - - protected override async Task ExecuteAsync(CancellationToken stoppingToken) - { - while (true) - { - try - { - await PollAsync(stoppingToken); - } - catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested) - { - return; - } - catch (Exception ex) - { - logger.LogWarning(ex, "The archive could not be polled"); - } - try - { - await Task.Delay(Interval, time, stoppingToken); - } - catch (OperationCanceledException) - { - return; - } - } - } -} diff --git a/src/Chronos.Server/Storage/DatabaseBackupService.cs b/src/Chronos.Server/Storage/DatabaseBackupService.cs deleted file mode 100644 index 5b24086a..00000000 --- a/src/Chronos.Server/Storage/DatabaseBackupService.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Chronos.Data; -using Chronos.Server.Configuration; - -namespace Chronos.Server.Storage; - -/// -/// The daily VACUUM INTO copy of the index of a Windows server on SQLite (BRIEF §6.2: nightly, kept ×3) into -/// {DataPath}/backups. A server on PostgreSQL is backed up with PostgreSQL's own tools; this service then does nothing. -/// -public sealed class DatabaseBackupService(ChronosDatabase db, ServerOptions options, TimeProvider time, ILogger logger) : BackgroundService -{ - /// Folder of the copies. - public string Directory => Path.Combine(options.DataPath, "backups"); - - protected override Task ExecuteAsync(CancellationToken stoppingToken) - { - if (db.Dialect != Dialect.Sqlite) return Task.CompletedTask; - logger.LogInformation("Daily index backups go to {Directory}", Directory); - return DatabaseBackups.RunDailyAsync(db, Directory, time, stoppingToken); - } -} diff --git a/src/Chronos.Server/Storage/UploadMaintenance.cs b/src/Chronos.Server/Storage/UploadMaintenance.cs index abae41b8..69ddefdc 100644 --- a/src/Chronos.Server/Storage/UploadMaintenance.cs +++ b/src/Chronos.Server/Storage/UploadMaintenance.cs @@ -1,20 +1,28 @@ +using Chronos.Core.Localization; using Chronos.Core.Model; using Chronos.Data; +using Chronos.Data.Archiving.Jobs; +using Chronos.Data.Housekeeping; using Chronos.Data.Repositories; using Chronos.Server.Configuration; namespace Chronos.Server.Storage; +/// What one sweep of removed. +public sealed record UploadSweep(int Expired, int Files, int Records, int Tokens); + /// -/// Upload housekeeping (BRIEF §14.4): at start, uploads a crash left half-committed are settled; then every half hour -/// abandoned uploads expire, orphaned partial and staging files are removed, old upload records and dead tokens purged. +/// Upload housekeeping (BRIEF §14.4): at start, uploads a crash left half-committed are settled; the sweep (abandoned +/// uploads expire, orphaned partial and staging files are removed, old upload records and dead tokens purged) is the +/// of the upload-cleanup system schedule (owner review 2, R10), no longer a timer. /// public sealed class UploadMaintenance(ChronosDatabase db, ServerOptions options, ServerArchive archive, UploadStore store, TimeProvider time, ILogger logger) : BackgroundService { - private static readonly TimeSpan Interval = TimeSpan.FromMinutes(30); - private static readonly TimeSpan FinishedRetention = TimeSpan.FromDays(90); + /// Days a finished upload's record is kept unless the schedule says otherwise. + public const int FinishedRetentionDays = 90; + private static readonly TimeSpan StagingRetention = TimeSpan.FromDays(1); protected override async Task ExecuteAsync(CancellationToken stoppingToken) @@ -27,22 +35,6 @@ public sealed class UploadMaintenance(ChronosDatabase db, ServerOptions options, { logger.LogError(ex, "Upload recovery failed"); } - while (!stoppingToken.IsCancellationRequested) - { - try - { - await SweepAsync(stoppingToken); - await Task.Delay(Interval, time, stoppingToken); - } - catch (OperationCanceledException) - { - return; - } - catch (Exception ex) - { - logger.LogWarning(ex, "Upload cleanup failed"); - } - } } /// @@ -77,7 +69,12 @@ public sealed class UploadMaintenance(ChronosDatabase db, ServerOptions options, return UploadRules.StandIn(archive.Root, copies, target); } - public async Task SweepAsync(CancellationToken cancellationToken) + /// + /// Expires uploads untouched for , deletes partial files no upload + /// receives into and this server's staging files older than a day, purges the records of uploads finished more than + /// days ago (0 keeps them) and expired tokens. Safe to run at any time. + /// + public async Task SweepAsync(int finishedDays = FinishedRetentionDays, CancellationToken cancellationToken = default) { var now = time.GetUtcNow(); var abandonedBefore = now - TimeSpan.FromHours(options.UploadRetentionHours); @@ -92,23 +89,49 @@ public sealed class UploadMaintenance(ChronosDatabase db, ServerOptions options, var active = new HashSet(); foreach (var state in new[] { UploadState.Receiving, UploadState.Committing }) active.UnionWith((await db.Uploads.ListByStateAsync(state, cancellationToken)).Select(u => u.Id)); + var files = 0; foreach (var (id, _) in store.List().ToList()) { - if (!active.Contains(id)) store.Delete(id); + if (active.Contains(id)) continue; + store.Delete(id); + if (!store.Exists(id)) files++; } if (Directory.Exists(options.StagingPath)) { // Only this server's staging files (named by upload id) are touched; clients may share the archive. foreach (var file in new DirectoryInfo(options.StagingPath).EnumerateFiles()) { - if (Guid.TryParseExact(Path.GetFileNameWithoutExtension(file.Name), "N", out var id) && !active.Contains(id) - && file.LastWriteTimeUtc < now.UtcDateTime - StagingRetention) - UploadStore.TryDelete(file.FullName); + if (!Guid.TryParseExact(Path.GetFileNameWithoutExtension(file.Name), "N", out var id) || active.Contains(id) + || file.LastWriteTimeUtc >= now.UtcDateTime - StagingRetention) + continue; + UploadStore.TryDelete(file.FullName); + if (!File.Exists(file.FullName)) files++; } } - await db.Uploads.PurgeFinishedAsync(now - FinishedRetention, cancellationToken); - await db.Tokens.PurgeAsync(now, cancellationToken); + var records = finishedDays > 0 ? await db.Uploads.PurgeFinishedAsync(now - TimeSpan.FromDays(finishedDays), cancellationToken) : 0; + var tokens = await db.Tokens.PurgeAsync(now, cancellationToken); if (expired > 0) logger.LogInformation("Expired {Count} abandoned upload(s)", expired); + return new UploadSweep(expired, files, records, tokens); + } +} + +/// +/// The server's own clean-up step uploads (owner review 2, R10): , with the +/// clean-up's age limit as the days finished upload records are kept. It deletes only what uploads left behind, never a +/// photo of the archive. +/// +public sealed class UploadCleanupStep(UploadMaintenance maintenance) : ICleanupStep +{ + public const string StepName = "uploads"; + + public string Name => StepName; + + public async Task RunAsync(CleanupContext context, CleanupParameters parameters) + { + ArgumentNullException.ThrowIfNull(context); + ArgumentNullException.ThrowIfNull(parameters); + var sweep = await maintenance.SweepAsync(parameters.OlderThanDays, context.Cancellation).ConfigureAwait(false); + return Loc.L("Server.Log.UploadsSwept", sweep.Expired, sweep.Files, sweep.Records, sweep.Tokens); } } diff --git a/tests/Chronos.Data.Tests/Repositories/JobRepositoryTests.cs b/tests/Chronos.Data.Tests/Repositories/JobRepositoryTests.cs index 66477324..fec31f7c 100644 --- a/tests/Chronos.Data.Tests/Repositories/JobRepositoryTests.cs +++ b/tests/Chronos.Data.Tests/Repositories/JobRepositoryTests.cs @@ -50,6 +50,27 @@ public abstract class JobRepositoryTests(TestContext context) : RepositoryTest(c Assert.Empty(await db.Jobs.ListByScheduleAsync(Guid.CreateVersion7(), cancellationToken: Ct)); } + [Test] + public async Task JobsOfAScheduleArePagedNewestFirst() + { + // The runs a schedule's row lists in the admin panel (owner review 2, R10). + var db = await OpenChronosAsync(); + var schedule = Guid.CreateVersion7(); + var jobs = new List(); + for (var i = 0; i < 3; i++) jobs.Add(await EnqueueAsync(db, TestData.Job(created: TestData.Now.AddMinutes(i)) with { ScheduleId = schedule })); + await EnqueueAsync(db, TestData.Job(created: TestData.Now.AddMinutes(5))); + + var first = await db.Jobs.PageByScheduleAsync(schedule, 2, null, Ct); + Assert.SequenceEqual([jobs[2].Id, jobs[1].Id], first.Items.Select(j => j.Id)); + var second = await db.Jobs.PageByScheduleAsync(schedule, 2, Assert.NotNull(first.NextCursor), Ct); + Assert.SequenceEqual([jobs[0].Id], second.Items.Select(j => j.Id)); + Assert.Null(second.NextCursor); + Assert.Empty((await db.Jobs.PageByScheduleAsync(Guid.CreateVersion7(), cancellationToken: Ct)).Items); + // A cursor of another listing is refused. + var other = await db.Jobs.ListAsync(null, 1, null, Ct); + await Assert.ThrowsAsync(() => db.Jobs.PageByScheduleAsync(schedule, 2, Assert.NotNull(other.NextCursor), Ct)); + } + [Test] public async Task PendingJobsAreFoundByKindAndTarget() { diff --git a/tests/Chronos.Server.Tests/Jobs/ScheduleEndpointTests.cs b/tests/Chronos.Server.Tests/Jobs/ScheduleEndpointTests.cs new file mode 100644 index 00000000..1243072f --- /dev/null +++ b/tests/Chronos.Server.Tests/Jobs/ScheduleEndpointTests.cs @@ -0,0 +1,465 @@ +using System.Net; +using System.Net.Http.Json; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging.Abstractions; +using Chronos.Core.Model; +using Chronos.Data.Jobs; +using Chronos.Data.Scheduling; +using Chronos.Protocol; +using Chronos.Server.Configuration; +using Chronos.Server.Jobs; +using Chronos.Server.Storage; +using Chronos.Testing; + +namespace Chronos.Server.Tests.Jobs; + +/// +/// /api/v1/schedules and the server's system schedules (owner review 2, R10): every timer the server ran is a visible +/// schedule, seeded once, edited, reset and run like the others; the old timers are gone. +/// +[Category("server")] +public sealed class ScheduleEndpointTests(TestContext context) +{ + private static readonly string[] SystemKeys = + [ServerScheduleHost.ArchiveScan, ServerScheduleHost.UploadCleanup, ServerScheduleHost.IndexBackup, ServerScheduleHost.Housekeeping, ServerScheduleHost.AuditCleanup]; + + private CancellationToken Ct => context.Cancellation; + + [Test] + public async Task TheSystemSchedulesTheActionsAndTheTimeZoneAreListed() + { + await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register); + var list = await ListAsync(await server.AdminAsync()); + + // The timers the server ran before, with their timings: nothing runs that this list does not show. + Assert.SequenceEqual(SystemKeys, list.Items.Select(s => s.SystemKey)); + var scan = SystemRow(list, ServerScheduleHost.ArchiveScan); + Assert.Equal(("scan", new RecurrenceDto("every", 10, "minutes"), false, "background", true), (scan.Action, scan.Recurrence, scan.CatchUp, scan.Priority, scan.Enabled)); + Assert.NotNull(scan.NextRun); + var uploads = SystemRow(list, ServerScheduleHost.UploadCleanup); + Assert.Equal(("cleanup", new RecurrenceDto("every", 30, "minutes"), true, (int?)90), (uploads.Action, uploads.Recurrence, uploads.CatchUp, uploads.Parameters.OlderThanDays)); + Assert.SequenceEqual([UploadCleanupStep.StepName], uploads.Parameters.Steps!); + var backup = SystemRow(list, ServerScheduleHost.IndexBackup); + Assert.Equal(("backup", new RecurrenceDto("daily", Time: "03:00"), true, (int?)3), (backup.Action, backup.Recurrence, backup.CatchUp, backup.Parameters.Keep)); + var history = SystemRow(list, ServerScheduleHost.Housekeeping); + Assert.Equal((new RecurrenceDto("daily", Time: "04:00"), (int?)90), (history.Recurrence, history.Parameters.OlderThanDays)); + Assert.SequenceEqual(["job-history"], history.Parameters.Steps!); + var audit = SystemRow(list, ServerScheduleHost.AuditCleanup); + Assert.Equal((new RecurrenceDto("daily", Time: "04:30"), (int?)365, true), (audit.Recurrence, audit.Parameters.OlderThanDays, audit.Enabled)); + Assert.SequenceEqual(["audit"], audit.Parameters.Steps!); + + // Every action, with whether this server runs it: without the processing module there is no analysis. + Assert.SequenceEqual(ScheduleActions.All, list.Actions.Select(a => a.Name)); + Assert.Equal((false, "no-handler"), (list.Actions.Single(a => a.Name == "analysis").Available, list.Actions.Single(a => a.Name == "analysis").Reason)); + Assert.True(list.Actions.Where(a => a.Name != "analysis").All(a => a.Available), string.Join(", ", list.Actions.Select(a => $"{a.Name}:{a.Reason}"))); + Assert.SequenceEqual(["job-history", "audit", "trash-report", UploadCleanupStep.StepName], list.Steps!); + Assert.Equal(server.Services.GetRequiredService().TimeZone.Id, list.TimeZone); + } + + [Test] + public async Task SchedulesAreCreatedChangedAndDeleted() + { + await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register); + var admin = await server.AdminAsync(); + + var created = await CreateAsync(admin, new CreateScheduleRequest("Weekly check", "verify", new RecurrenceDto("weekly", Time: "02:30", Days: ["thu", "mon"]), + new ScheduleParametersDto(OlderThanDays: 60, Percent: 25))); + Assert.Equal(("Weekly check", "verify", "current", "background", true, (string?)null), (created.Name, created.Action, created.Target, created.Priority, created.Enabled, created.SystemKey)); + Assert.SequenceEqual(["mon", "thu"], created.Recurrence.Days!); + Assert.Equal(((int?)60, (int?)25), (created.Parameters.OlderThanDays, created.Parameters.Percent)); + Assert.NotNull(created.NextRun); + // After the system schedules. + Assert.Equal(created.Id, (await ListAsync(admin)).Items[^1].Id); + + // PUT replaces the fields it gives; disabled, a schedule has no next run. + using (var put = await admin.PutAsJsonAsync($"/api/v1/schedules/{created.Id}", + new UpdateScheduleRequest(Recurrence: new RecurrenceDto("every", 2, "hours"), Priority: "normal", Enabled: false), ProtocolJson.Default.UpdateScheduleRequest)) + { + var updated = await put.ReadAsync(ProtocolJson.Default.ScheduleDto); + Assert.Equal((new RecurrenceDto("every", 2, "hours"), "normal", false, (DateTimeOffset?)null, (int?)25), + (updated.Recurrence, updated.Priority, updated.Enabled, updated.NextRun, updated.Parameters.Percent)); + } + // PATCH does the same: enabled again, it gets a next run. + using (var patch = await admin.PatchAsJsonAsync($"/api/v1/schedules/{created.Id}", new UpdateScheduleRequest(Enabled: true, Name: "Check"), + ProtocolJson.Default.UpdateScheduleRequest)) + { + var enabled = await patch.ReadAsync(ProtocolJson.Default.ScheduleDto); + Assert.Equal(("Check", true), (enabled.Name, enabled.Enabled)); + Assert.NotNull(enabled.NextRun); + } + using (var one = await admin.GetAsync($"/api/v1/schedules/{created.Id}")) Assert.Equal("Check", (await one.ReadAsync(ProtocolJson.Default.ScheduleDto)).Name); + + using (var delete = await admin.DeleteAsync($"/api/v1/schedules/{created.Id}")) await delete.ExpectAsync(HttpStatusCode.NoContent); + using (var gone = await admin.GetAsync($"/api/v1/schedules/{created.Id}")) await gone.ExpectErrorAsync(HttpStatusCode.NotFound, "not_found"); + using (var again = await admin.DeleteAsync($"/api/v1/schedules/{created.Id}")) await again.ExpectErrorAsync(HttpStatusCode.NotFound, "not_found"); + Assert.SequenceEqual(SystemKeys, (await ListAsync(admin)).Items.Select(s => s.SystemKey)); + + // Every change is in the audit log. + using var audit = await admin.GetAsync("/api/v1/audit?action=schedule_created,schedule_updated,schedule_deleted"); + var entries = (await audit.ReadAsync(ProtocolJson.Default.PageAuditEntryDto)).Items; + Assert.SequenceEqual(["schedule_deleted", "schedule_updated", "schedule_updated", "schedule_created"], entries.Select(e => e.Action)); + Assert.True(entries.All(e => e.TargetId == created.Id.ToString() && e.Username == "admin"), "target and user"); + Assert.Equal("Weekly check · verify · weekly:mon,thu@02:30", entries[^1].Details); + Assert.Equal(("Weekly check · verify · every:2h · off", "Check · verify · every:2h"), (entries[2].Details, entries[1].Details)); + } + + [Test] + public async Task OnlyArchiveAdministratorsSeeAndChangeSchedules() + { + await using var server = await TestServer.StartAsync(context); + var (editor, _, _) = await server.UserAsync("alberto", "editor"); + using (var list = await editor.GetAsync("/api/v1/schedules")) await list.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden"); + using (var create = await editor.PostAsJsonAsync("/api/v1/schedules", new CreateScheduleRequest("Mine", "scan", new RecurrenceDto("daily", Time: "01:00")), + ProtocolJson.Default.CreateScheduleRequest)) + await create.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden"); + var scan = Assert.NotNull(await server.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.ArchiveScan, Ct)); + using (var run = await editor.PostAsync($"/api/v1/schedules/{scan.Id}/run", null)) await run.ExpectErrorAsync(HttpStatusCode.Forbidden, "forbidden"); + using (var anonymous = await server.Client.GetAsync("/api/v1/schedules")) Assert.Equal(HttpStatusCode.Unauthorized, anonymous.StatusCode); + } + + [Test] + public async Task InvalidFieldsAreNamed() + { + await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register); + var admin = await server.AdminAsync(); + var daily = new RecurrenceDto("daily", Time: "03:00"); + var cases = new (CreateScheduleRequest Request, string Field)[] + { + (new(" ", "scan", daily), "name"), + (new(new string('x', Scheduler.MaxNameLength + 1), "scan", daily), "name"), + (new("Render", "render", daily), "action"), + (new("Often", "scan", new RecurrenceDto("every", 1, "minutes")), "recurrence"), + (new("No days", "scan", new RecurrenceDto("weekly", Time: "03:00", Days: [])), "recurrence"), + (new("Late", "scan", new RecurrenceDto("daily", Time: "25:00")), "recurrence"), + (new("Day 31", "scan", new RecurrenceDto("monthly", Time: "03:00", DayOfMonth: 31)), "recurrence"), + (new("None", "verify", daily, new ScheduleParametersDto(Percent: 0)), "parameters.percent"), + (new("Old", "verify", daily, new ScheduleParametersDto(OlderThanDays: -1)), "parameters.olderThanDays"), + (new("Copies", "backup", daily, new ScheduleParametersDto(Keep: 0)), "parameters.keep"), + (new("Unknown step", "cleanup", daily, new ScheduleParametersDto(Steps: ["photos"])), "parameters.steps"), + (new("No step", "cleanup", daily, new ScheduleParametersDto(Steps: [])), "parameters.steps"), + (new("Urgent", "scan", daily, Priority: "urgent"), "priority"), + (new("Elsewhere", "scan", daily, Target: "another-archive"), "target"), + }; + foreach (var (request, field) in cases) + { + using var response = await admin.PostAsJsonAsync("/api/v1/schedules", request, ProtocolJson.Default.CreateScheduleRequest); + var error = await response.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_schedule"); + Assert.Equal(field, error.Details, request.Name); + Assert.Contains(field, error.Message); + } + Assert.Count(SystemKeys.Length, (await ListAsync(admin)).Items); + } + + [Test] + public async Task SystemSchedulesAreEditedAndResetButNeverDeleted() + { + await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register); + var admin = await server.AdminAsync(); + var housekeeping = SystemRow(await ListAsync(admin), ServerScheduleHost.Housekeeping); + + using (var delete = await admin.DeleteAsync($"/api/v1/schedules/{housekeeping.Id}")) await delete.ExpectErrorAsync(HttpStatusCode.Conflict, "schedule_system"); + foreach (var (request, field) in new[] { (new UpdateScheduleRequest(Name: "Mine"), "name"), (new UpdateScheduleRequest(Action: "verify"), "action") }) + { + using var refused = await admin.PutAsJsonAsync($"/api/v1/schedules/{housekeeping.Id}", request, ProtocolJson.Default.UpdateScheduleRequest); + Assert.Equal(field, (await refused.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_schedule")).Details); + } + + // Its timing, its parameters and its switch change like any schedule's; the same name and action may be sent back. + using (var edit = await admin.PutAsJsonAsync($"/api/v1/schedules/{housekeeping.Id}", new UpdateScheduleRequest(housekeeping.Name, "cleanup", + new RecurrenceDto("weekly", Time: "05:15", Days: ["sun"]), new ScheduleParametersDto(Steps: ["job-history", "trash-report"], OlderThanDays: 30), + CatchUp: false, Enabled: false), ProtocolJson.Default.UpdateScheduleRequest)) + { + var edited = await edit.ReadAsync(ProtocolJson.Default.ScheduleDto); + Assert.Equal(("weekly", (int?)30, false, false), (edited.Recurrence.Kind, edited.Parameters.OlderThanDays, edited.CatchUp, edited.Enabled)); + } + + // Reset puts the server's defaults back, with a new next run. + using (var reset = await admin.PostAsync($"/api/v1/schedules/{housekeeping.Id}/reset", null)) + { + var back = await reset.ReadAsync(ProtocolJson.Default.ScheduleDto); + Assert.Equal((new RecurrenceDto("daily", Time: "04:00"), (int?)90, true, true), (back.Recurrence, back.Parameters.OlderThanDays, back.CatchUp, back.Enabled)); + Assert.SequenceEqual(["job-history"], back.Parameters.Steps!); + Assert.NotNull(back.NextRun); + } + + var custom = await CreateAsync(admin, new CreateScheduleRequest("Mine", "duplicates", new RecurrenceDto("monthly", Time: "01:00", DayOfMonth: 1))); + using (var notSystem = await admin.PostAsync($"/api/v1/schedules/{custom.Id}/reset", null)) + await notSystem.ExpectErrorAsync(HttpStatusCode.Conflict, "schedule_no_defaults"); + using (var unknown = await admin.PostAsync($"/api/v1/schedules/{Guid.CreateVersion7()}/reset", null)) await unknown.ExpectErrorAsync(HttpStatusCode.NotFound, "not_found"); + + using var audit = await admin.GetAsync("/api/v1/audit?action=schedule_reset"); + Assert.Equal(housekeeping.Id.ToString(), (await audit.ReadAsync(ProtocolJson.Default.PageAuditEntryDto)).Items.Single().TargetId); + } + + [Test] + public async Task TheJobHistoryOfTheSettingsIsWhatTheHousekeepingScheduleIsResetTo() + { + await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register); + var admin = await server.AdminAsync(); + using (var read = await admin.GetAsync("/api/v1/server/settings")) + { + var settings = await read.ReadAsync(ProtocolJson.Default.ServerSettingsDto); + // The test server listens on ports the OS chose, which the settings refuse: real ones are sent with the edit. + using var saved = await admin.PutAsJsonAsync("/api/v1/server/settings", settings with { JobHistoryDays = 30, HttpPort = 18080, HttpsPort = 18443 }, + ProtocolJson.Default.ServerSettingsDto); + await saved.ExpectAsync(HttpStatusCode.OK); + } + // The schedule keeps its own value; a reset takes the new one, without a restart. + Assert.Equal(30, server.Options.JobHistoryDays); + var housekeeping = SystemRow(await ListAsync(admin), ServerScheduleHost.Housekeeping); + Assert.Equal((int?)90, housekeeping.Parameters.OlderThanDays); + using var reset = await admin.PostAsync($"/api/v1/schedules/{housekeeping.Id}/reset", null); + Assert.Equal((int?)30, (await reset.ReadAsync(ProtocolJson.Default.ScheduleDto)).Parameters.OlderThanDays); + } + + [Test] + public async Task RunNowQueuesTheJobsOnceAndListsThemAsRuns() + { + var handler = new BlockingJobHandler(JobKind.Duplicates); + await using var server = await TestServer.StartAsync(context, services: s => s.AddSingleton(handler)); + var admin = await server.AdminAsync(); + // Also a disabled schedule runs now. + var schedule = await CreateAsync(admin, new CreateScheduleRequest("Duplicates", "duplicates", new RecurrenceDto("daily", Time: "01:00"), Enabled: false)); + + var first = await RunAsync(admin, schedule.Id); + Assert.Equal("queued", first.Outcome); + var job = await JobApiTests.WaitForAsync(admin, first.JobId!.Value, "running"); + Assert.Equal(("duplicates", (Guid?)schedule.Id, "background"), (job.Kind, job.ScheduleId, job.Priority)); + Assert.Equal((first.JobId, "queued", (DateTimeOffset?)null), (first.Schedule.LastJobId, first.Schedule.LastOutcome, first.Schedule.NextRun)); + + // While its last job has not ended, it is not run again. + using (var busy = await admin.PostAsync($"/api/v1/schedules/{schedule.Id}/run", null)) + Assert.Equal(first.JobId.ToString(), (await busy.ExpectErrorAsync(HttpStatusCode.Conflict, "schedule_pending")).Details); + handler.Release(); + await JobApiTests.WaitForAsync(admin, first.JobId!.Value, "done"); + + var second = await RunAsync(admin, schedule.Id); + Assert.Equal("queued", second.Outcome); + await JobApiTests.WaitForAsync(admin, second.JobId!.Value, "running"); + handler.Release(); + await JobApiTests.WaitForAsync(admin, second.JobId!.Value, "done"); + + // Its runs, newest first, a page at a time. + using (var page1 = await admin.GetAsync($"/api/v1/schedules/{schedule.Id}/runs?limit=1")) + { + var runs = await page1.ReadAsync(ProtocolJson.Default.PageJobDto); + Assert.Equal(second.JobId, runs.Items.Single().Id); + using var page2 = await admin.GetAsync($"/api/v1/schedules/{schedule.Id}/runs?limit=1&cursor={Uri.EscapeDataString(Assert.NotNull(runs.NextCursor))}"); + var rest = await page2.ReadAsync(ProtocolJson.Default.PageJobDto); + Assert.Equal((first.JobId, (string?)null), (rest.Items.Single().Id, rest.NextCursor)); + } + using (var bad = await admin.GetAsync($"/api/v1/schedules/{schedule.Id}/runs?cursor=nonsense")) await bad.ExpectErrorAsync(HttpStatusCode.BadRequest, "invalid_cursor"); + using (var unknown = await admin.GetAsync($"/api/v1/schedules/{Guid.CreateVersion7()}/runs")) await unknown.ExpectErrorAsync(HttpStatusCode.NotFound, "not_found"); + using (var other = await admin.PostAsync($"/api/v1/schedules/{Guid.CreateVersion7()}/run", null)) await other.ExpectErrorAsync(HttpStatusCode.NotFound, "not_found"); + + // The queue shows which jobs a schedule queued. + using (var queue = await admin.GetAsync("/api/v1/jobs?kind=duplicates")) + Assert.True((await queue.ReadAsync(ProtocolJson.Default.PageJobDto)).Items.All(j => j.ScheduleId == schedule.Id), "scheduleId on the job rows"); + + using var audit = await admin.GetAsync("/api/v1/audit?action=schedule_run"); + Assert.SequenceEqual(["Duplicates · queued", "Duplicates · queued"], (await audit.ReadAsync(ProtocolJson.Default.PageAuditEntryDto)).Items.Select(e => e.Details)); + } + + [Test] + public async Task SystemSchedulesAreSeededOnceAndKeepTheirEditsAcrossRestarts() + { + var root = context.CreateTempDirectory("restart"); + void Paths(ServerOptions o) + { + o.DataPath = Path.Combine(root, "data"); + o.ArchivePath = Path.Combine(root, "archive"); + Directory.CreateDirectory(o.ArchivePath); + } + Guid scanId; + DateTimeOffset? lastRun; + await using (var first = await TestServer.StartAsync(context, Paths)) + { + var admin = await first.AdminAsync(); + scanId = SystemRow(await ListAsync(admin), ServerScheduleHost.ArchiveScan).Id; + // Its run at start (no scan handler here: "unavailable") is recorded before the edit. + var until = DateTime.UtcNow + TimeSpan.FromSeconds(30); + while ((lastRun = (await first.Database.Schedules.GetAsync(scanId, Ct))!.LastRun) is null) + { + Assert.True(DateTime.UtcNow < until, "no run at start"); + await Task.Delay(20); + } + using var put = await admin.PutAsJsonAsync($"/api/v1/schedules/{scanId}", new UpdateScheduleRequest(Recurrence: new RecurrenceDto("every", 20, "minutes"), Enabled: false), + ProtocolJson.Default.UpdateScheduleRequest); + await put.ExpectAsync(HttpStatusCode.OK); + } + + await using var second = await TestServer.StartAsync(context, Paths); + var rows = await second.Database.Schedules.ListAsync(Ct); + Assert.SequenceEqual(SystemKeys, rows.Select(s => s.SystemKey)); + var scan = rows.Single(s => s.SystemKey == ServerScheduleHost.ArchiveScan); + Assert.Equal((scanId, "every:20m", false, (DateTimeOffset?)null), (scan.Id, scan.Recurrence, scan.Enabled, scan.NextRun)); + // Disabled, the scan does not run at start either. + Assert.Equal(lastRun, scan.LastRun); + } + + [Test] + public async Task TheScanScheduleQueuesAScanWhenDueAndNoTimerScansBesideIt() + { + var clock = new ManualTimeProvider(); + await using var server = await TestServer.StartAsync(context, services: s => + { + ArchiveModule.Register(s); + s.AddSingleton(clock); + }); + var hosted = server.Services.GetServices().Select(h => h.GetType().Name).ToList(); + Assert.Contains(nameof(SchedulerHost), hosted); + Assert.True(hosted.IndexOf(nameof(JobEngineHost)) < hosted.IndexOf(nameof(SchedulerHost)), "the scheduler starts after the engine"); + Assert.True(!hosted.Contains("ArchivePolling") && !hosted.Contains("DatabaseBackupService"), string.Join(", ", hosted)); + var scheduleId = Assert.NotNull(await server.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.ArchiveScan, Ct)).Id; + + // At start the scan schedule runs once, as the polling did; no other scan is queued. + var scans = await ScansAsync(server, 1); + Assert.Equal(scheduleId, scans.Single().ScheduleId); + + // Ten minutes later it is due: the next pass queues the second scan. + clock.Advance(TimeSpan.FromMinutes(11)); + await server.Services.GetRequiredService().Scheduler.RunDueAsync(Ct); + scans = await ScansAsync(server, 2); + Assert.True(scans.All(j => j.ScheduleId == scheduleId && j.Priority == JobPriority.Background), "scans of the schedule, in the background"); + var row = Assert.NotNull(await server.Database.Schedules.GetAsync(scheduleId, Ct)); + Assert.Equal(("queued", (Guid?)scans[^1].Id), (row.LastOutcome, row.LastJobId)); + Assert.True(row.NextRun > clock.GetUtcNow(), "the next run moved on"); + } + + [Test] + public async Task TheUploadCleanupScheduleSweepsAbandonedUploadsLikeTheFormerTimer() + { + var clock = new ManualTimeProvider(); + await using var server = await TestServer.StartAsync(context, o => o.UploadRetentionHours = 48, s => + { + ArchiveModule.Register(s); + s.AddSingleton(clock); + }); + var (uploader, _, _) = await server.UserAsync("roof-cam", "uploader"); + var id = (await Uploads.StartAsync(uploader, Uploads.Photo(1000, 10))).UploadId!.Value; + var store = server.Services.GetRequiredService(); + Assert.True(store.Exists(id)); + var scheduleId = Assert.NotNull(await server.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.UploadCleanup, Ct)).Id; + + // Two days later its half-hourly run expires the upload and deletes its partial file. + clock.Advance(TimeSpan.FromHours(49)); + await server.Services.GetRequiredService().Scheduler.RunDueAsync(Ct); + var until = DateTime.UtcNow + TimeSpan.FromSeconds(30); + Job? sweep = null; + while (sweep is not { State: JobState.Done }) + { + Assert.True(DateTime.UtcNow < until, $"the clean-up did not finish: {sweep?.State} {sweep?.Error}"); + await Task.Delay(50); + sweep = (await server.Database.Jobs.ListByScheduleAsync(scheduleId, cancellationToken: Ct)).FirstOrDefault(); + } + Assert.Equal(JobKind.Cleanup, sweep.Kind); + Assert.Contains("Uploads expired: 1", sweep.LogTail); + Assert.False(store.Exists(id)); + using var state = await uploader.GetAsync($"/api/v1/uploads/{id}"); + Assert.Equal("cancelled", (await state.ReadAsync(ProtocolJson.Default.UploadState)).State); + } + + [Test] + public async Task AnAuditRetentionFromTheEnvironmentIsAppliedAtStartAndCannotBeChanged() + { + var root = context.CreateTempDirectory("locked"); + void Paths(ServerOptions o) + { + o.DataPath = Path.Combine(root, "data"); + o.ArchivePath = Path.Combine(root, "archive"); + Directory.CreateDirectory(o.ArchivePath); + } + await using (var first = await TestServer.StartAsync(context, Paths, ArchiveModule.Register)) + { + var seeded = Assert.NotNull(await first.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.AuditCleanup, Ct)); + Assert.Equal((int?)365, ScheduleMapping.Parameters(seeded).OlderThanDays); + } + + // CHRONOS_AUDIT_RETENTION_DAYS=30 at the next start. + await using var second = await TestServer.StartAsync(context, o => + { + Paths(o); + o.AuditRetentionDays = 30; + o.Locked = [nameof(ServerOptions.AuditRetentionDays)]; + }, ArchiveModule.Register); + var admin = await second.AdminAsync(); + var audit = SystemRow(await ListAsync(admin), ServerScheduleHost.AuditCleanup); + Assert.Equal(((int?)30, true), (audit.Parameters.OlderThanDays, audit.Enabled)); + + using (var changed = await admin.PutAsJsonAsync($"/api/v1/schedules/{audit.Id}", new UpdateScheduleRequest(Parameters: new ScheduleParametersDto(Steps: ["audit"], OlderThanDays: 60)), + ProtocolJson.Default.UpdateScheduleRequest)) + Assert.Equal("AuditRetentionDays", (await changed.ExpectErrorAsync(HttpStatusCode.Conflict, "setting_locked")).Details); + // Everything else stays editable. + using var timing = await admin.PutAsJsonAsync($"/api/v1/schedules/{audit.Id}", new UpdateScheduleRequest(Recurrence: new RecurrenceDto("daily", Time: "05:00"), + Parameters: new ScheduleParametersDto(Steps: ["audit", "job-history"], OlderThanDays: 30)), ProtocolJson.Default.UpdateScheduleRequest); + await timing.ExpectAsync(HttpStatusCode.OK); + } + + [Test] + public void AnUnknownTimeZoneFallsBackToUtc() + { + var local = ServerScheduleHost.ResolveTimeZone(null, NullLogger.Instance); + Assert.Equal(TimeZoneInfo.Local.BaseUtcOffset, local.BaseUtcOffset); + Assert.Equal(TimeZoneInfo.Local.SupportsDaylightSavingTime, local.SupportsDaylightSavingTime); + // The runtime ignores TZ on Windows; elsewhere a zone it cannot find would leave the schedules in an unknown zone. + if (!OperatingSystem.IsWindows()) + { + Assert.Equal(TimeZoneInfo.Utc, ServerScheduleHost.ResolveTimeZone("Not/AZone", NullLogger.Instance)); + Assert.Equal(TimeZoneInfo.Local.Id, ServerScheduleHost.ResolveTimeZone(":" + TimeZoneInfo.Local.Id, NullLogger.Instance).Id); + } + } + + [Test] + public void TheAuditRetentionVariableIsReadAndChecked() + { + var data = context.CreateTempDirectory("env"); + var options = ServerOptions.Load(new Dictionary { ["CHRONOS_DATA_PATH"] = data, ["CHRONOS_DB"] = "postgres", [ServerOptions.AuditRetentionVariable] = "0" }); + Assert.Equal(0, options.AuditRetentionDays); + Assert.Contains(nameof(ServerOptions.AuditRetentionDays), options.Locked); + Assert.Equal(365, new ServerOptions().AuditRetentionDays); + foreach (var invalid in new[] { "-1", "3651", "a year" }) + { + Assert.Throws(() => + ServerOptions.Load(new Dictionary { ["CHRONOS_DATA_PATH"] = data, ["CHRONOS_DB"] = "postgres", [ServerOptions.AuditRetentionVariable] = invalid })); + } + } + + /// Scan jobs, oldest first, once exist and none is waiting or running. + private async Task> ScansAsync(TestServer server, int count) + { + var until = DateTime.UtcNow + TimeSpan.FromSeconds(30); + while (true) + { + var scans = (await server.Database.Jobs.ListAsync(null, JobKind.Scan, 50, null, Ct)).Items.OrderBy(j => j.Created).ToList(); + if (scans.Count >= count && scans.All(j => j.State is JobState.Done or JobState.Failed or JobState.Cancelled)) + { + Assert.Count(count, scans); + return scans; + } + Assert.True(DateTime.UtcNow < until, $"{scans.Count} scan(s): {string.Join(", ", scans.Select(j => j.State))}"); + await Task.Delay(50); + } + } + + private static ScheduleDto SystemRow(SchedulesDto list, string key) => list.Items.Single(s => s.SystemKey == key); + + private static async Task ListAsync(HttpClient admin) + { + using var response = await admin.GetAsync("/api/v1/schedules"); + return await response.ReadAsync(ProtocolJson.Default.SchedulesDto); + } + + private static async Task CreateAsync(HttpClient admin, CreateScheduleRequest request) + { + using var response = await admin.PostAsJsonAsync("/api/v1/schedules", request, ProtocolJson.Default.CreateScheduleRequest); + await response.ExpectAsync(HttpStatusCode.Created); + return await response.ReadAsync(ProtocolJson.Default.ScheduleDto); + } + + private static async Task RunAsync(HttpClient admin, Guid id) + { + using var response = await admin.PostAsync($"/api/v1/schedules/{id}/run", null); + return await response.ReadAsync(ProtocolJson.Default.ScheduleRunDto); + } +} diff --git a/tests/Chronos.Server.Tests/Postgres/PostgresServerTests.cs b/tests/Chronos.Server.Tests/Postgres/PostgresServerTests.cs index cfa54b1b..d3593f74 100644 --- a/tests/Chronos.Server.Tests/Postgres/PostgresServerTests.cs +++ b/tests/Chronos.Server.Tests/Postgres/PostgresServerTests.cs @@ -67,6 +67,32 @@ public sealed class PostgresServerTests(TestContext context) await Api.SequenceTests.FramesOfOneVersionAsync(server); } + [Test] + public async Task SchedulesRunOnPostgresWithoutAnIndexBackup() + { + await using var schema = await Schema.CreateAsync(context); + await using var server = await TestServer.StartAsync(context, o => + { + o.Database = DatabaseKind.Postgres; + o.DbConnectionString = schema.ConnectionString; + }, Chronos.Server.Storage.ArchiveModule.Register); + var admin = await server.AdminAsync(); + using var response = await admin.GetAsync("/api/v1/schedules"); + var list = await response.ReadAsync(ProtocolJson.Default.SchedulesDto); + + // PostgreSQL is backed up with its own tools (owner review 2, R10): no index-backup schedule, and the action says why. + Assert.SequenceEqual(["archive-scan", "upload-cleanup", "housekeeping", "audit-cleanup"], list.Items.Select(s => s.SystemKey)); + var backup = list.Actions.Single(a => a.Name == "backup"); + Assert.Equal((false, "postgres"), (backup.Available, backup.Reason)); + + // A run is claimed, queued and recorded on PostgreSQL as on SQLite. + var history = list.Items.Single(s => s.SystemKey == "housekeeping"); + using var run = await admin.PostAsync($"/api/v1/schedules/{history.Id}/run", null); + var ran = await run.ReadAsync(ProtocolJson.Default.ScheduleRunDto); + Assert.Equal(("queued", ran.JobId), (ran.Outcome, ran.Schedule.LastJobId)); + await JobApiTests.WaitForAsync(admin, ran.JobId!.Value, "done"); + } + /// A throw-away schema on the test server, selected through Search Path. private sealed class Schema : IAsyncDisposable { diff --git a/tests/Chronos.Server.Tests/Storage/ArchiveModuleTests.cs b/tests/Chronos.Server.Tests/Storage/ArchiveModuleTests.cs index 59782dc9..282b7c89 100644 --- a/tests/Chronos.Server.Tests/Storage/ArchiveModuleTests.cs +++ b/tests/Chronos.Server.Tests/Storage/ArchiveModuleTests.cs @@ -52,12 +52,16 @@ public sealed class ArchiveModuleTests(TestContext context) } [Test] - public async Task AServerOnSqliteBacksUpItsIndexOnStart() + public async Task TheIndexBackupScheduleCopiesAnSqliteIndexIntoTheDataFolder() { await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register); var backups = Path.Combine(server.Options.DataPath, "backups"); - // No copy yet, so the first one is made at once (BRIEF §6.2), named after the index it copies. + // The nightly copy (BRIEF §6.2) is the index-backup system schedule's (owner review 2, R10), here run now. + var schedule = Assert.NotNull(await server.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.IndexBackup, context.Cancellation)); + Assert.Equal("daily:03:00", schedule.Recurrence); + var run = Assert.NotNull(await server.Services.GetRequiredService().Scheduler.RunNowAsync(schedule.Id, null, context.Cancellation)); + Assert.Equal("queued", run.Outcome); var until = DateTime.UtcNow + TimeSpan.FromSeconds(30); while (!Directory.Exists(backups) || Directory.GetFiles(backups, "*.db").Length == 0) { @@ -71,7 +75,7 @@ public sealed class ArchiveModuleTests(TestContext context) } [Test] - public async Task PhotosAlreadyInTheArchiveAndAddedLaterAreIndexedByPollingWithThumbnailsAndProxies() + public async Task PhotosAlreadyInTheArchiveAndAddedLaterAreIndexedByTheScanScheduleWithThumbnailsAndProxies() { var photo = Photo(); // An adopted folder that already holds photos. @@ -87,10 +91,9 @@ public sealed class ArchiveModuleTests(TestContext context) // The scan queues the thumbnails and proxies clients load from the server, as an upload does. await UntilImagesAsync(server, editor, archive.Id, "roof"); - // Another writer adds a folder: the next poll queues a scan, but not while one is pending. + // Another writer adds a folder: the next run of the scan schedule queues a scan, but not while one is pending. Directory.CreateDirectory(Path.Combine(server.Options.ArchivePath, "garden")); File.WriteAllBytes(Path.Combine(server.Options.ArchivePath, "garden", "IMG_0002.JPG"), Photo(seed: 3)); - var polling = server.Services.GetRequiredService(); var paused = new Job { Id = Guid.CreateVersion7(), @@ -100,11 +103,13 @@ public sealed class ArchiveModuleTests(TestContext context) Created = DateTimeOffset.UtcNow, }; await server.Database.Jobs.EnqueueAsync(paused, context.Cancellation); - Assert.Null(await polling.PollAsync(context.Cancellation)); + Assert.Equal("skipped-pending", (await RunScanAsync(server)).Outcome); await server.Services.GetRequiredService().Engine.CancelAsync(paused.Id, context.Cancellation); - var scan = Assert.NotNull(await polling.PollAsync(context.Cancellation)); - Assert.Equal(JobPriority.Background, scan.Priority); + var run = await RunScanAsync(server); + Assert.Equal("queued", run.Outcome); + var scan = Assert.NotNull(await server.Database.Jobs.GetAsync(run.JobId!.Value, context.Cancellation)); + Assert.Equal((JobKind.Scan, JobPriority.Background, (Guid?)run.Schedule.Id), (scan.Kind, scan.Priority, scan.ScheduleId)); await UntilIndexedAsync(server, archive.Id, "garden"); await UntilImagesAsync(server, editor, archive.Id, "garden"); } @@ -141,8 +146,8 @@ public sealed class ArchiveModuleTests(TestContext context) } Assert.Equal(1, Assert.NotNull(await server.Database.Sequences.GetAsync(roof.Id)).FrameCount); - // The next poll indexes it and queues the images: the new frame and the one it moved get theirs. - Assert.NotNull(await server.Services.GetRequiredService().PollAsync(context.Cancellation)); + // The scan schedule's next run indexes it and queues the images: the new frame and the one it moved get theirs. + Assert.Equal("queued", (await RunScanAsync(server)).Outcome); await UntilScannedAsync(server); Assert.Equal(2, Assert.NotNull(await server.Database.Sequences.GetAsync(roof.Id)).FrameCount); await UntilImagesAsync(server, editor, archive.Id, "roof"); @@ -182,11 +187,12 @@ public sealed class ArchiveModuleTests(TestContext context) { await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register); var archive = server.Services.GetRequiredService(); - var polling = server.Services.GetRequiredService(); + // Every run of a schedule reads the archive through its host, which takes archive.json's settings first. + var schedules = server.Services.GetRequiredService(); // Nothing changed: the served archive (the one an administrator's edit put there) is not replaced by a row read again. var served = archive.Current; - await polling.PollAsync(context.Cancellation); - Assert.True(ReferenceEquals(served, archive.Current), "a poll that registered nothing keeps the served archive"); + await schedules.GetArchiveAsync(context.Cancellation); + Assert.True(ReferenceEquals(served, archive.Current), "a refresh that registered nothing keeps the served archive"); // A desktop sharing the archive changed its folder template and proxy size in archive.json. var path = new ArchivePaths(archive.Root).ManifestPath; @@ -197,14 +203,14 @@ public sealed class ArchiveModuleTests(TestContext context) ProxyPolicy = manifest.ProxyPolicy with { LongEdge = 2560 }, }); - await polling.PollAsync(context.Cancellation); + Assert.Equal("{camera}/{date}", Assert.NotNull(await schedules.GetArchiveAsync(context.Cancellation)).FolderTemplate); // Uploads (the index row) and the admin panel (the served archive) follow it. Assert.Equal(("{camera}/{date}", 2560), (archive.Current.FolderTemplate, archive.Current.ProxyLongEdge)); var row = Assert.NotNull(await server.Database.Archives.GetAsync(archive.Id, context.Cancellation)); Assert.Equal(("{camera}/{date}", 2560), (row.FolderTemplate, row.ProxyLongEdge)); - // The admin panel opens before the next poll: its form, which saves every field, starts from the desktop's change. + // The admin panel opens before the next run: its form, which saves every field, starts from the desktop's change. ManifestStore.WriteArchive(path, ManifestStore.ReadArchive(path) with { LayoutTemplates = manifest.LayoutTemplates with { Folder = "{year}/{camera}" } }); var admin = await server.AdminAsync(); using (var read = await admin.GetAsync("/api/v1/archive/settings")) @@ -275,6 +281,13 @@ public sealed class ArchiveModuleTests(TestContext context) } } + /// Runs the archive-scan system schedule now, as its next run would. + private static async Task RunScanAsync(TestServer server) + { + var schedule = Assert.NotNull(await server.Database.Schedules.GetBySystemKeyAsync(ServerScheduleHost.ArchiveScan)); + return Assert.NotNull(await server.Services.GetRequiredService().Scheduler.RunNowAsync(schedule.Id, null)); + } + /// Waits for the scan queued at start to finish: its sequences are indexed before it ends. private static async Task UntilScannedAsync(TestServer server) { diff --git a/tests/Chronos.Server.Tests/Storage/UploadTests.cs b/tests/Chronos.Server.Tests/Storage/UploadTests.cs index 2453bf9d..2d4afee5 100644 --- a/tests/Chronos.Server.Tests/Storage/UploadTests.cs +++ b/tests/Chronos.Server.Tests/Storage/UploadTests.cs @@ -335,7 +335,7 @@ public sealed class UploadTests(TestContext context) // Upload rows carry real timestamps; the sweep looks 48 h past the moved clock. clock.Advance(TimeSpan.FromHours(49)); - await server.Services.GetRequiredService().SweepAsync(context.Cancellation); + await server.Services.GetRequiredService().SweepAsync(cancellationToken: context.Cancellation); Assert.False(store.Exists(id)); using var state = await uploader.GetAsync($"/api/v1/uploads/{id}"); Assert.Equal("cancelled", (await state.ReadAsync(ProtocolJson.Default.UploadState)).State);