mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
#6768: the recovery scan retried every pending activity notification each round, and one whose delivery fails for good - its activity deleted or changed since, a recipient who lost access, a plan with nothing or too much to send - failed the same way every round, forever, so the list only grew. Such an error is terminal now: after a ten-minute grace (an activity being written is never touched) the scan cancels that notification through the same cancellation an administrator uses, as the system, which compacts it to a cancelled receipt. A pending notification older than ACTIVITY_NOTIFICATION_MAX_AGE_DAYS (7) is cancelled as expired instead of being delivered a week late. Network and other transient failures are still retried. Admin Panel -> Problems gets "Retry all" and "Cancel older..." for the whole list at once, site administrators only. #6769: before each run synced-cron asks whether a job of that name is still running - { name, finishedAt: { $exists: false } } - every minute for every job on every instance, and only { intendedAt, name } and the TTL on startedAt were indexed, so it scanned the job history. { name, finishedAt } is created at startup with WeKan's ensureIndex. The new strings are translated in every locale. Thanks to Raymond-Voogt and xet7 ! Fixes #6768, Fixes #6769.
79 lines
2.5 KiB
JavaScript
79 lines
2.5 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
|
|
let syncedCronConfigured = false;
|
|
let syncedCronInstance = null;
|
|
|
|
function getSyncedCronInstance() {
|
|
if (!syncedCronInstance) {
|
|
syncedCronInstance = require('meteor/quave:synced-cron').SyncedCron;
|
|
}
|
|
return syncedCronInstance;
|
|
}
|
|
|
|
export function configureSyncedCron() {
|
|
if (syncedCronConfigured) {
|
|
return;
|
|
}
|
|
|
|
const SyncedCron = getSyncedCronInstance();
|
|
SyncedCron.config({
|
|
log: false,
|
|
collectionName: 'cronJobs',
|
|
utc: false,
|
|
collectionTTL: 172800,
|
|
});
|
|
|
|
syncedCronConfigured = true;
|
|
}
|
|
|
|
export function startSyncedCron() {
|
|
configureSyncedCron();
|
|
getSyncedCronInstance().start();
|
|
}
|
|
|
|
export const SyncedCron = new Proxy(
|
|
{},
|
|
{
|
|
get(_target, prop) {
|
|
return getSyncedCronInstance()[prop];
|
|
},
|
|
set(_target, prop, value) {
|
|
getSyncedCronInstance()[prop] = value;
|
|
return true;
|
|
},
|
|
},
|
|
);
|
|
|
|
// Configure before the package's startup hook creates its history collection.
|
|
// Registration alone does not start timers (quave:synced-cron's add() only
|
|
// schedules immediately once running). The removed migration bootstrap was the
|
|
// last caller of startSyncedCron, leaving backups/rules registered but idle.
|
|
configureSyncedCron();
|
|
Meteor.startup(async () => {
|
|
startSyncedCron();
|
|
// The package makes its collection in its own startup; if it is not there
|
|
// yet, ask again a little later rather than leave the scan in place.
|
|
if (!(await ensureCronIndexes()) && !getSyncedCronInstance()._collection && typeof setTimeout === 'function') {
|
|
setTimeout(() => { ensureCronIndexes(); }, 5000);
|
|
}
|
|
});
|
|
|
|
// #6769: before running a job, synced-cron asks whether one of that name is
|
|
// still running - `{ name, finishedAt: { $exists: false } }` - every minute
|
|
// for every job on every instance. The package indexes only
|
|
// `{ intendedAt, name }` and the TTL on `startedAt`, so that question scanned
|
|
// the whole history: thousands of documents with many pods and a 48-hour TTL.
|
|
// `{ name, finishedAt }` answers it from the index.
|
|
export const CRON_RUNNING_JOB_INDEX = { name: 1, finishedAt: 1 };
|
|
export async function ensureCronIndexes() {
|
|
try {
|
|
const collection = getSyncedCronInstance()._collection;
|
|
if (!collection) return false;
|
|
const { ensureIndex } = require('/server/lib/mongoStartup');
|
|
return await ensureIndex(collection, CRON_RUNNING_JOB_INDEX);
|
|
} catch (error) {
|
|
console.error('SyncedCron: could not index the running-job lookup:', error && error.message);
|
|
return false;
|
|
}
|
|
}
|