import cloud from '@lafjs/cloud'; import { currentPassStart, freezeUser } from '@/passCheckSettlement'; /** Bounded durable scans also backfill players who were offline when this job was deployed. */ export default async function () { await currentPassStart(); const db: any = cloud.mongo.db; let count = 0; for (const table of ['users', 'usersAd']) { const cursors = db.collection('passCheckJobCursors'); const cursor = await cursors.findOne({ _id: table }); const rows = await db.collection(table).find(cursor?.after ? { _id: { $gt: cursor.after } } : {}).sort({ _id: 1 }).limit(100).toArray(); // A failed row leaves the cursor unchanged, so the next run retries the batch. for (const user of rows) { await freezeUser(user, table); count++; } await cursors.updateOne({ _id: table }, { $set: { after: rows.length === 100 ? rows[rows.length - 1]._id : null } }, { upsert: true }); } return { count }; }