Files
wekan/models/recoveryStatus.js
T
Lauri Ojansivu 9ea7f11d27 Show a full-page maintenance spinner while data recovery is in progress
#6492: while the SQLite text data is being recovered/remediated, users should see a
maintenance spinner instead of errors or half-loaded data.

- A published singleton status (models/recoveryStatus.js) carries an "active" flag +
  message. The publication (server/publications/recoveryMaintenance.js) is PUBLIC so
  even logged-out users on the sign-in page see it; the toggle method
  (setRecoveryMaintenance) is admin-only.
- The client overlay (client/components/main/recoveryMaintenance.*) shows a full-screen
  spinner + message when active; it is subscribed globally and rendered in both the app
  (defaultLayout) and sign-in (userFormsLayout) layouts, above modals/popups.
- The startup scripts write a RECOVERY_IN_PROGRESS marker when they restore/re-migrate.
  On startup the WeKan server (server/recovery.js) shows the spinner while the marker is
  present, verifies the database serves reads (probe), then clears the marker and the
  spinner — or, if it still cannot read, keeps the spinner and records that manual
  recovery is required. Admins can also toggle maintenance for a server-initiated
  re-migration.

Tests: tests/recoveryMaintenance.test.cjs (wired into npm run test:unit:node) — the
publication is public while the toggle is admin-gated, the overlay is subscribed and
rendered in both layouts above everything, the server shows the spinner from the marker
and clears it only after a health probe, and the scripts write the marker. Mirror-
validated (no Node runtime here); shell/brace/JSON all checked.

Thanks to bluetopaz1204, mueschel and xet7 !

Fixes #6492,
2026-07-21 10:06:41 +03:00

46 lines
1.6 KiB
JavaScript

import { Mongo } from 'meteor/mongo';
// #6492 Recovery maintenance status — a single published document that tells every
// client (logged in or not) that a data recovery / remediation is in progress, so the
// UI can show a full-page maintenance spinner instead of errors or half-loaded data.
const RecoveryStatus = new Mongo.Collection('recoveryStatus');
// The one document id. Only the server ever writes it.
const RECOVERY_STATUS_ID = 'recovery-status';
// setMaintenance turns the maintenance spinner on/off with an optional message.
// Server-only and best-effort (never throws into the recovery flow).
RecoveryStatus.setMaintenance = async function setMaintenance(active, message) {
if (!Meteor.isServer) {
return null;
}
try {
return await RecoveryStatus.upsertAsync(
{ _id: RECOVERY_STATUS_ID },
{ $set: { active: !!active, message: message || '', updatedAt: new Date() } },
);
} catch (e) {
if (process.env.DEBUG === 'true') {
// eslint-disable-next-line no-console
console.error('RecoveryStatus.setMaintenance failed:', e && e.message);
}
return null;
}
};
// isMaintenanceActive reports the current flag (reactive on the client via the
// published document).
RecoveryStatus.isMaintenanceActive = function isMaintenanceActive() {
const doc = RecoveryStatus.findOne(RECOVERY_STATUS_ID);
return !!(doc && doc.active);
};
RecoveryStatus.maintenanceMessage = function maintenanceMessage() {
const doc = RecoveryStatus.findOne(RECOVERY_STATUS_ID);
return (doc && doc.message) || '';
};
export { RECOVERY_STATUS_ID };
export default RecoveryStatus;