Files
wekan/server/lib/tests/syncedCronIndex.tests.js
T
Lauri Ojansivu e0317a9ff3 Drain the activity notification recovery list; index synced-cron's lookup.
#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.
2026-10-14 14:00:21 +03:00

27 lines
1.4 KiB
JavaScript

import assert from 'node:assert/strict';
import { Meteor } from 'meteor/meteor';
import { ensureCronIndexes, CRON_RUNNING_JOB_INDEX } from '/server/cron/syncedCron';
// #6769 on a running server: synced-cron's "is this job still running"
// lookup - { name, finishedAt: { $exists: false } }, every minute per job and
// instance - is answered from an index, not a scan of the job history.
describe('SyncedCron running-job index (#6769)', function () {
this.timeout(30000);
before(function () { if (!Meteor.isAppTest) this.skip(); });
it('cronJobs has { name, finishedAt } and the lookup uses it', async function () {
await ensureCronIndexes();
const { SyncedCron } = require('meteor/quave:synced-cron');
const raw = SyncedCron._collection.rawCollection();
const indexes = await raw.indexes();
assert.ok(indexes.some(i => JSON.stringify(i.key) === JSON.stringify(CRON_RUNNING_JOB_INDEX)), JSON.stringify(indexes.map(i => i.key)));
const plan = await raw.find({ name: 'wekan-scheduled-rules', finishedAt: { $exists: false } }).limit(1).explain();
// MongoDB names the plan; FerretDB's explain is shaped differently, so the
// plan is checked only where it is MongoDB's.
const winning = plan && plan.queryPlanner && JSON.stringify(plan.queryPlanner.winningPlan);
if (winning) assert.doesNotMatch(winning, /COLLSCAN/);
// A second run adds nothing.
assert.equal(await ensureCronIndexes(), false);
});
});