snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
205
apps/meteor/ee/server/cron/readReceiptsArchive.spec.ts
Normal file
205
apps/meteor/ee/server/cron/readReceiptsArchive.spec.ts
Normal file
@@ -0,0 +1,205 @@
|
||||
import { ReadReceipts, ReadReceiptsArchive, Messages } from '@rocket.chat/models';
|
||||
|
||||
import { archiveOldReadReceipts } from './readReceiptsArchive';
|
||||
import { settings } from '../../../server/settings';
|
||||
|
||||
jest.mock('@rocket.chat/models', () => ({
|
||||
ReadReceipts: {
|
||||
findOlderThan: jest.fn(),
|
||||
removeByIds: jest.fn(),
|
||||
},
|
||||
ReadReceiptsArchive: {
|
||||
insertMany: jest.fn(),
|
||||
},
|
||||
Messages: {
|
||||
setReceiptsArchivedById: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('@rocket.chat/logger', () => ({
|
||||
Logger: jest.fn().mockImplementation(() => ({
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
jest.mock('../../../server/settings', () => ({
|
||||
settings: {
|
||||
get: jest.fn(),
|
||||
watch: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('@rocket.chat/cron', () => ({
|
||||
cronJobs: {
|
||||
add: jest.fn(),
|
||||
has: jest.fn(),
|
||||
remove: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock setTimeout to avoid actual delays in tests
|
||||
jest.useFakeTimers();
|
||||
|
||||
describe('Read Receipts Archive', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.runOnlyPendingTimers();
|
||||
});
|
||||
|
||||
it('should use default retention days and batch size when settings are not available', async () => {
|
||||
(settings.get as jest.Mock).mockReturnValue(undefined);
|
||||
|
||||
const limitMock = jest.fn().mockReturnValue({ toArray: jest.fn().mockResolvedValue([]) });
|
||||
(ReadReceipts.findOlderThan as jest.Mock).mockReturnValue({ limit: limitMock });
|
||||
|
||||
await archiveOldReadReceipts();
|
||||
|
||||
expect(ReadReceipts.findOlderThan).toHaveBeenCalled();
|
||||
expect(limitMock).toHaveBeenCalledWith(10000); // Default batch size
|
||||
const cutoffDate = (ReadReceipts.findOlderThan as jest.Mock).mock.calls[0][0];
|
||||
const daysDiff = Math.floor((Date.now() - cutoffDate.getTime()) / (24 * 60 * 60 * 1000));
|
||||
expect(daysDiff).toBe(30); // Default 30 days
|
||||
});
|
||||
|
||||
it('should use configured retention days and batch size', async () => {
|
||||
(settings.get as jest.Mock).mockImplementation((key: string) => {
|
||||
if (key === 'Message_Read_Receipt_Archive_Retention_Days') return 45;
|
||||
if (key === 'Message_Read_Receipt_Archive_Batch_Size') return 5000;
|
||||
return undefined;
|
||||
});
|
||||
|
||||
const limitMock = jest.fn().mockReturnValue({ toArray: jest.fn().mockResolvedValue([]) });
|
||||
(ReadReceipts.findOlderThan as jest.Mock).mockReturnValue({ limit: limitMock });
|
||||
|
||||
await archiveOldReadReceipts();
|
||||
|
||||
expect(ReadReceipts.findOlderThan).toHaveBeenCalled();
|
||||
expect(limitMock).toHaveBeenCalledWith(5000); // Custom batch size
|
||||
const cutoffDate = (ReadReceipts.findOlderThan as jest.Mock).mock.calls[0][0];
|
||||
const daysDiff = Math.floor((Date.now() - cutoffDate.getTime()) / (24 * 60 * 60 * 1000));
|
||||
expect(daysDiff).toBe(45);
|
||||
});
|
||||
|
||||
it('should not process when no old receipts found', async () => {
|
||||
(settings.get as jest.Mock).mockReturnValue(30);
|
||||
|
||||
const limitMock = jest.fn().mockReturnValue({ toArray: jest.fn().mockResolvedValue([]) });
|
||||
(ReadReceipts.findOlderThan as jest.Mock).mockReturnValue({ limit: limitMock });
|
||||
|
||||
await archiveOldReadReceipts();
|
||||
|
||||
expect(ReadReceiptsArchive.insertMany).not.toHaveBeenCalled();
|
||||
expect(Messages.setReceiptsArchivedById).not.toHaveBeenCalled();
|
||||
expect(ReadReceipts.removeByIds).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should archive old receipts in single batch and mark messages', async () => {
|
||||
(settings.get as jest.Mock).mockReturnValue(30);
|
||||
|
||||
const oldReceipts = [
|
||||
{ _id: '1', messageId: 'msg1', userId: 'user1', ts: new Date('2020-01-01') },
|
||||
{ _id: '2', messageId: 'msg2', userId: 'user2', ts: new Date('2020-01-02') },
|
||||
{ _id: '3', messageId: 'msg1', userId: 'user3', ts: new Date('2020-01-03') },
|
||||
];
|
||||
|
||||
const limitMock = jest.fn().mockReturnValue({ toArray: jest.fn().mockResolvedValue(oldReceipts) });
|
||||
(ReadReceipts.findOlderThan as jest.Mock).mockReturnValue({ limit: limitMock });
|
||||
(ReadReceiptsArchive.insertMany as jest.Mock).mockResolvedValue({ insertedCount: 3 });
|
||||
(Messages.setReceiptsArchivedById as jest.Mock).mockResolvedValue({ modifiedCount: 2 });
|
||||
(ReadReceipts.removeByIds as jest.Mock).mockResolvedValue({ deletedCount: 3 });
|
||||
|
||||
await archiveOldReadReceipts();
|
||||
|
||||
// Verify insertMany was called with receipts
|
||||
expect(ReadReceiptsArchive.insertMany).toHaveBeenCalledWith(oldReceipts, { ordered: false });
|
||||
|
||||
// Verify messages were marked
|
||||
expect(Messages.setReceiptsArchivedById).toHaveBeenCalledWith(['msg1', 'msg2'], true);
|
||||
|
||||
// Verify old receipts were deleted by ID
|
||||
expect(ReadReceipts.removeByIds).toHaveBeenCalledWith(['1', '2', '3']);
|
||||
});
|
||||
|
||||
it('should process multiple batches with delay', async () => {
|
||||
(settings.get as jest.Mock).mockImplementation((key: string) => {
|
||||
if (key === 'Message_Read_Receipt_Archive_Retention_Days') return 30;
|
||||
if (key === 'Message_Read_Receipt_Archive_Batch_Size') return 2;
|
||||
return undefined;
|
||||
});
|
||||
|
||||
const batch1 = [
|
||||
{ _id: '1', messageId: 'msg1', userId: 'user1', ts: new Date('2020-01-01') },
|
||||
{ _id: '2', messageId: 'msg2', userId: 'user2', ts: new Date('2020-01-02') },
|
||||
];
|
||||
const batch2 = [{ _id: '3', messageId: 'msg3', userId: 'user3', ts: new Date('2020-01-03') }];
|
||||
|
||||
let callCount = 0;
|
||||
const limitMock = jest.fn().mockImplementation(() => ({
|
||||
toArray: jest.fn().mockImplementation(() => {
|
||||
callCount++;
|
||||
if (callCount === 1) return Promise.resolve(batch1);
|
||||
if (callCount === 2) return Promise.resolve(batch2);
|
||||
return Promise.resolve([]);
|
||||
}),
|
||||
}));
|
||||
|
||||
(ReadReceipts.findOlderThan as jest.Mock).mockReturnValue({ limit: limitMock });
|
||||
(ReadReceiptsArchive.insertMany as jest.Mock).mockResolvedValue({ insertedCount: 2 });
|
||||
(Messages.setReceiptsArchivedById as jest.Mock).mockResolvedValue({ modifiedCount: 1 });
|
||||
(ReadReceipts.removeByIds as jest.Mock).mockResolvedValue({ deletedCount: 2 });
|
||||
|
||||
const archivePromise = archiveOldReadReceipts();
|
||||
|
||||
// Fast-forward timers for delays between batches
|
||||
await jest.runAllTimersAsync();
|
||||
await archivePromise;
|
||||
|
||||
// Should process 2 batches
|
||||
expect(ReadReceiptsArchive.insertMany).toHaveBeenCalledTimes(2);
|
||||
expect(Messages.setReceiptsArchivedById).toHaveBeenCalledTimes(2);
|
||||
expect(ReadReceipts.removeByIds).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should handle duplicate key errors gracefully', async () => {
|
||||
(settings.get as jest.Mock).mockReturnValue(30);
|
||||
|
||||
const oldReceipts = [{ _id: '1', messageId: 'msg1', userId: 'user1', ts: new Date('2020-01-01') }];
|
||||
|
||||
const limitMock = jest.fn().mockReturnValue({ toArray: jest.fn().mockResolvedValue(oldReceipts) });
|
||||
(ReadReceipts.findOlderThan as jest.Mock).mockReturnValue({ limit: limitMock });
|
||||
|
||||
// Simulate duplicate key error
|
||||
const duplicateError = Object.assign(new Error('Duplicate key'), {
|
||||
code: 11000,
|
||||
result: { insertedCount: 0 },
|
||||
});
|
||||
(ReadReceiptsArchive.insertMany as jest.Mock).mockRejectedValue(duplicateError);
|
||||
(Messages.setReceiptsArchivedById as jest.Mock).mockResolvedValue({ modifiedCount: 1 });
|
||||
(ReadReceipts.removeByIds as jest.Mock).mockResolvedValue({ deletedCount: 1 });
|
||||
|
||||
await archiveOldReadReceipts();
|
||||
|
||||
// Should continue despite duplicate error
|
||||
expect(Messages.setReceiptsArchivedById).toHaveBeenCalled();
|
||||
expect(ReadReceipts.removeByIds).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should rethrow non-duplicate errors', async () => {
|
||||
(settings.get as jest.Mock).mockReturnValue(30);
|
||||
|
||||
const oldReceipts = [{ _id: '1', messageId: 'msg1', userId: 'user1', ts: new Date('2020-01-01') }];
|
||||
|
||||
const limitMock = jest.fn().mockReturnValue({ toArray: jest.fn().mockResolvedValue(oldReceipts) });
|
||||
(ReadReceipts.findOlderThan as jest.Mock).mockReturnValue({ limit: limitMock });
|
||||
|
||||
// Simulate other error
|
||||
const otherError = new Error('Connection failed');
|
||||
(ReadReceiptsArchive.insertMany as jest.Mock).mockRejectedValue(otherError);
|
||||
|
||||
await expect(archiveOldReadReceipts()).rejects.toThrow('Connection failed');
|
||||
});
|
||||
});
|
||||
116
apps/meteor/ee/server/cron/readReceiptsArchive.ts
Normal file
116
apps/meteor/ee/server/cron/readReceiptsArchive.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import { cronJobs } from '@rocket.chat/cron';
|
||||
import { Logger } from '@rocket.chat/logger';
|
||||
import { ReadReceipts, ReadReceiptsArchive, Messages } from '@rocket.chat/models';
|
||||
|
||||
import { sleep } from '../../../lib/utils/sleep';
|
||||
import { settings } from '../../../server/settings';
|
||||
|
||||
const logger = new Logger('ReadReceiptsArchive');
|
||||
|
||||
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
|
||||
const BATCH_DELAY_MS = 1000; // 1 second delay between batches
|
||||
|
||||
export async function archiveOldReadReceipts(): Promise<void> {
|
||||
const retentionDays = settings.get<number>('Message_Read_Receipt_Archive_Retention_Days') || 30;
|
||||
const batchSize = settings.get<number>('Message_Read_Receipt_Archive_Batch_Size') || 10000;
|
||||
const cutoffDate = new Date(Date.now() - retentionDays * MILLISECONDS_PER_DAY);
|
||||
|
||||
logger.info({ msg: 'Starting to archive old read receipts', batchSize, cutoffDate });
|
||||
|
||||
let totalProcessed = 0;
|
||||
let batchNumber = 0;
|
||||
let hasMore = true;
|
||||
|
||||
while (hasMore) {
|
||||
batchNumber++;
|
||||
logger.info({ msg: 'Processing batch', batchNumber });
|
||||
|
||||
// Find receipts older than the retention period, limited by batch size
|
||||
|
||||
const oldReceipts = await ReadReceipts.findOlderThan(cutoffDate).limit(batchSize).toArray();
|
||||
|
||||
if (oldReceipts.length === 0) {
|
||||
logger.info({ msg: 'No more read receipts to archive', totalProcessed });
|
||||
break;
|
||||
}
|
||||
|
||||
logger.info({ msg: 'Found read receipts in batch', count: oldReceipts.length, batchNumber });
|
||||
|
||||
// Get unique message IDs from the receipts to be archived
|
||||
const messageIds = [...new Set(oldReceipts.map((receipt) => receipt.messageId))];
|
||||
|
||||
try {
|
||||
// Insert receipts into archive collection (using insertMany with ordered: false to continue on duplicate key errors)
|
||||
try {
|
||||
await ReadReceiptsArchive.insertMany(oldReceipts, { ordered: false });
|
||||
logger.info({ msg: 'Successfully archived read receipts', count: oldReceipts.length, batchNumber });
|
||||
} catch (error: unknown) {
|
||||
// If we get duplicate key errors, some receipts were already archived, which is fine
|
||||
// We'll continue to mark messages and delete from hot storage
|
||||
if (error && typeof error === 'object' && ('code' in error || 'writeErrors' in error)) {
|
||||
const mongoError = error as {
|
||||
code?: number;
|
||||
result?: { insertedCount?: number };
|
||||
writeErrors?: Array<{ code?: number }>;
|
||||
};
|
||||
const onlyDuplicateErrors = mongoError.writeErrors?.length
|
||||
? mongoError.writeErrors.every((writeError) => writeError.code === 11000)
|
||||
: mongoError.code === 11000;
|
||||
|
||||
if (onlyDuplicateErrors) {
|
||||
const insertedCount = mongoError.result?.insertedCount || 0;
|
||||
logger.info({ msg: 'Archived read receipts (some were already archived)', insertedCount, batchNumber });
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Mark messages as having archived receipts
|
||||
|
||||
const updateResult = await Messages.setReceiptsArchivedById(messageIds, true);
|
||||
logger.info({ msg: 'Marked messages as having archived receipts', modifiedCount: updateResult.modifiedCount, batchNumber });
|
||||
|
||||
// Delete old receipts from hot storage for this batch
|
||||
const receiptIds = oldReceipts.map((receipt) => receipt._id);
|
||||
|
||||
const deleteResult = await ReadReceipts.removeByIds(receiptIds);
|
||||
logger.info({ msg: 'Deleted old receipts from hot storage', deletedCount: deleteResult.deletedCount, batchNumber });
|
||||
|
||||
totalProcessed += oldReceipts.length;
|
||||
|
||||
// If we processed a full batch, there might be more, so wait and continue
|
||||
if (oldReceipts.length === batchSize) {
|
||||
logger.info({ msg: 'Batch complete, waiting before next batch', batchNumber, delayMs: BATCH_DELAY_MS });
|
||||
|
||||
await sleep(BATCH_DELAY_MS);
|
||||
} else {
|
||||
// This was the last batch (partial batch)
|
||||
logger.info({ msg: 'Final batch complete', batchNumber, totalProcessed });
|
||||
hasMore = false;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error({ msg: 'Error during read receipts archiving', batchNumber, err: error });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function readReceiptsArchiveCron(): Promise<void> {
|
||||
const cronSchedule = settings.get<string>('Message_Read_Receipt_Archive_Cron') || '0 2 * * *';
|
||||
|
||||
// Remove existing job if it exists
|
||||
if (await cronJobs.has('ReadReceiptsArchive')) {
|
||||
await cronJobs.remove('ReadReceiptsArchive');
|
||||
}
|
||||
|
||||
if (!settings.get<boolean>('Message_Read_Receipt_Archive_Enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info({ msg: 'Scheduling read receipts archive cron job', cronSchedule });
|
||||
|
||||
return cronJobs.add('ReadReceiptsArchive', cronSchedule, async () => archiveOldReadReceipts());
|
||||
}
|
||||
Reference in New Issue
Block a user