mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 07:33:17 +00:00
fix: history cron job breaking on mysql (#21616)
* fix: history cron job breaking on mysql * fix: backend unit test * fix: use js date instead of string
This commit is contained in:
parent
840550dc97
commit
80bde34977
@ -97,6 +97,6 @@ describe('history lifecycles service', () => {
|
||||
await lifecyclesService.bootstrap();
|
||||
|
||||
expect(mockScheduleJob).toHaveBeenCalledTimes(1);
|
||||
expect(mockScheduleJob).toHaveBeenCalledWith('0 0 * * *', expect.any(Function));
|
||||
expect(mockScheduleJob).toHaveBeenCalledWith('historyDaily', '0 0 * * *', expect.any(Function));
|
||||
});
|
||||
});
|
||||
|
||||
@ -172,17 +172,24 @@ const createLifecyclesService = ({ strapi }: { strapi: Core.Strapi }) => {
|
||||
});
|
||||
|
||||
// Schedule a job to delete expired history versions every day at midnight
|
||||
state.deleteExpiredJob = scheduleJob('0 0 * * *', () => {
|
||||
state.deleteExpiredJob = scheduleJob('historyDaily', '0 0 * * *', () => {
|
||||
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1000;
|
||||
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
||||
|
||||
strapi.db.query(HISTORY_VERSION_UID).deleteMany({
|
||||
where: {
|
||||
created_at: {
|
||||
$lt: expirationDate.toISOString(),
|
||||
strapi.db
|
||||
.query(HISTORY_VERSION_UID)
|
||||
.deleteMany({
|
||||
where: {
|
||||
created_at: {
|
||||
$lt: expirationDate,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error instanceof Error) {
|
||||
strapi.log.error('Error deleting expired history versions', error.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
state.isInitialized = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user