-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
import { t } from '../../i18n/server'; | ||
import Base from '../../layouts/base.astro'; | ||
--- | ||
|
||
<Base title={t('proceeding-landing-expired', 'heading')}> | ||
{t('proceeding-landing-expired', 'explanation')} | ||
</Base> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-disable no-console */ | ||
import { CronJob } from 'cron'; | ||
import { client, e } from './lib/db'; | ||
|
||
const proceedingCompletedStates = [ | ||
'complaintSent', | ||
'secondAnalysisFoundNothing', | ||
'secondAnalysisFailed', | ||
'initialAnalysisFoundNothing', | ||
'initialAnalysisFailed', | ||
'expired', | ||
'erased', | ||
]; | ||
|
||
// Garbage collection | ||
new CronJob('08 12 03 * * *', async () => { | ||
console.log('Running garbage collection...'); | ||
|
||
// Proceedings expired after one year. | ||
const oneYearAgo = new Date(); | ||
oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1); | ||
|
||
const expiredProceedings = await e | ||
.update(e.Proceeding, (p) => ({ | ||
filter: e.all( | ||
e.set( | ||
e.op(p.state, 'not in', e.set(...proceedingCompletedStates)), | ||
e.op(p.createdOn, '<=', oneYearAgo), | ||
), | ||
), | ||
|
||
set: { expired: e.datetime_current() }, | ||
})) | ||
.run(client); | ||
console.log('Expired', expiredProceedings.length, 'proceedings.'); | ||
|
||
// Uploads of completed proceedings are deleted after one week. | ||
const oneWeekAgo = new Date(); | ||
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); | ||
|
||
const deletedCompletedUploads = await e | ||
.delete(e.MessageUpload, (u) => ({ | ||
filter: e.all( | ||
e.set( | ||
e.op(u.proceeding.state, 'in', e.set(...proceedingCompletedStates)), | ||
e.op(u.proceeding.stateUpdatedOn, '<=', oneWeekAgo), | ||
), | ||
), | ||
})) | ||
.run(client); | ||
console.log('Deleted', deletedCompletedUploads.length, 'uploads of completed proceedings.'); | ||
|
||
console.log('Finished garbage collection.'); | ||
console.log(); | ||
}).start(); | ||
/* eslint-enable no-console */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters