Repository navigation
feat(server,admin): scheduled jobs get a registry, run records and a Jobs page - #377
Merged
Merged
Conversation
… runs The server's scheduled jobs are declared once, in utils/jobs.ts: a name, a title, a description, the schedule, whether the job can be switched and whether it has a count mode. Every tick goes through one wrapper: it reads the job's mode at that tick, runs nothing when it is off, hands the mode to the job and records the run in job_runs, keeping the newest 200 per job. A mode that cannot be read is the job's default mode, with one warning per job per hour. A stored mode the job cannot run in runs nothing. A record that cannot be written is warned about and never fails the job. A job that runs more often than hourly is recorded only when its outcome changes, a count is not zero or it fails, and otherwise once an hour. A run's summary holds only counts and the words of a closed list, under keys the job declares; a failure is recorded as utils/loggableError.ts describes it. The migration 20261127120000_job_registry adds job_settings and job_runs. It is additive and goes in before the server that reads them.
Every tick of the nine scheduled jobs goes through the registry's wrapper: the presence reaper, the voice reaper, attachment expiry, registration hygiene, the object-store orphan sweep, report retention, the key-share sweep, the session sweep and the discovery cycle. The wrapper sits around each job's own lock: a job that is off claims no lock and runs nothing, and its next tick is armed as after a run. Each job keeps its lock, its schedule, its guards, its log lines and its return values. It tells the run what it counted, that another node held the lock (not recorded), that Redis could not be reached, that a guard or a bound refused the run, or that it caught its own error; a failed run is still logged by the job as before. The two reapers are not switchable and never read a mode. The admin triggers of the hygiene and orphan sweeps call the locked sweep directly: they are neither switched nor recorded. The server sets the database store at start, before the first job.
…h a job
GET /admin/jobs lists every job of the registry with its description, its
schedule, whether it can be switched, its mode and who set it, its last run
and its last failure, the next slot of a daily job, and whether it is
overdue (its last run older than twice the longest gap its records can
have). GET /admin/jobs/:name/runs pages one job's history newest first by
an explicit keyset on the run id (limit 1 to 100, 25 by default). Every
administrator may read them.
PUT /admin/jobs/:name { mode } is for superadmins: an unknown job or mode,
count on a job without it and any change to a job that cannot be switched
answer 400. A change is audited as job.update with the old and the new
mode, and answered with the job as the list shows it. The routes are on
the admin router, behind its authentication, administrator check and
limiter; their statements are in utils/jobStore.ts.
The audit log labels and offers job.update.
The navigation has a Jobs entry. Its page shows each scheduled job of the server with its description, its schedule, its mode, its last run (outcome, when, how long) and its next slot, and marks a job whose last run failed or that is overdue. Opening a job shows its runs, newest first and paged, with their counts and, for a failure, the error. A superadmin switches a job through the confirmation dialog; every other administrator reads the mode with the reason they cannot change it, and a job that cannot be switched shows why. A refused switch toasts the server's reason, leaves the dialog open and changes nothing on screen.
…led read A scheduled job that was switched off does not run because its mode could not be read. Only a missing settings table reads as the default mode, with one warning per job per hour. Any other failure of the read, its 10 s bound included, skips the tick: one error line per job per hour, and a run recorded as skipped (mode-unreadable). A job that is off cannot be run by hand either. The two manual admin triggers (registration hygiene, orphan clean-up) go through the registry: 409 "This job is switched off" while it is off, the error itself when the mode cannot be read, otherwise the run is recorded with the word "manual". A dry run reads only and stays outside the registry. The list shows what the server will do: a stored mode the job cannot run in is shown as not running, a row stored for a job that cannot be switched is ignored, a job that is on with no run on record says so, and the audit keeps the stored value as it was. A switch that was written is answered as done even when the read for the answer fails. A record never holds a network address: an error that carries a system error code is stored by name, code and status. For the jobs recorded on change, the same failure is recorded at most once in 15 minutes. A stored summary is read against the job's declared keys. The dashboard switches a mode with one button per mode and its confirmation, and applies a list answer only when no later request or switch has been answered since.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was missing
The server's scheduled jobs each had their own lock and log lines and no shared record. None could be switched off without a release, and an administrator could not see what a run did.
What the code does now
utils/jobs.tsdeclares every scheduled job once: name, title, a description of what it does, its schedule, whether it can be switched, whether it has a count-only mode, and its default mode. Nine jobs: attachment clean-up, registration hygiene, the object-store orphan clean-up, report retention, the key-share sweep, the session sweep, the discovery cycle, and the two 60-second reapers (presence, dead voice nodes).job_runs: when, on which node, the outcome (success, failed, skipped with its reason), the job's own counts, and a failure as the log describes it. A record holds numbers and a few fixed words only; a network error is stored by name and code. 200 runs are kept per job. The jobs that run every minute or every few minutes are recorded when something changes, and at most hourly when quiet.GET /admin/jobs,GET /admin/jobs/:name/runs(keyset paging),PUT /admin/jobs/:name(superadmin only, audited asjob.updatewith the old and the new mode).Key files
apps/server/src/utils/jobs.ts,apps/server/src/utils/jobStore.tsapps/server/src/routes/admin.ts(the scheduled-jobs routes and the two manual triggers)apps/server/prisma/migrations/20261127120000_job_registry/migration.sqlapps/admin/src/components/AdminJobs.tsx,apps/admin/src/stores/adminStore.tsMigrations
20261127120000_job_registry: additive. Two tables (job_settings,job_runs), one index, one key tousersadded under a lock timeout. It goes in before the server that reads it. A server older than it is unaffected. A server newer than it on a database without it runs every job in its default mode and records nothing.Tests
pnpm typecheck,pnpm lintand the server, admin and desktop unit suites pass on the branch.To check by hand