Auto-cleanup courses for ended semesters #455#502
Conversation
AdamFipke
left a comment
There was a problem hiding this comment.
Gave it an initial pass, see comments
| await LMSCourseIntegrationModel.delete({ | ||
| courseId: course.id, | ||
| }); |
There was a problem hiding this comment.
idk if this is all you have to do to cleanup a connection. @bhunt02 you will want to review this step
| await ChatbotDocPdfModel.delete({ | ||
| courseId: course.id, | ||
| }); |
There was a problem hiding this comment.
erm, this only deletes the full documents (used for citations). You should also delete the corresponding document (and its chunks) in the chatbot DB, basically copying the logic for deleteDocument() endpoint inside chatbot.controller.ts.
@Delete('document/:courseId/:docId')
@UseGuards(CourseRolesGuard)
@Roles(Role.PROFESSOR, Role.TA)
async deleteDocument(
@Param('courseId', ParseIntPipe) courseId: number,
@Param('docId') docId: string,
@User({ chat_token: true }) user: UserModel,
) {
handleChatbotTokenCheck(user);
const chatbotDeleteResponse = await this.chatbotApiService.deleteDocument(
docId,
courseId,
user.chat_token.token,
);
// if that succeeded (an error would have been thrown if it didn't), then delete the document from database
await ChatbotDocPdfModel.delete({
docIdChatbotDB: docId,
});
return chatbotDeleteResponse;
}I'm thinking you can just loop over all ChatbotDocPdfModel entities for the course and use that docIdChatbotDB to delete the corresponding documents using chatbotApiService.deleteDocument, and then if that succeeds, delete the ChatbotDocPdfModel
There was a problem hiding this comment.
Actually, you also need to figure out how to delete any LMS chunks too. Which means we might need a new endpoint in the chatbot repo for deleting all chunks and documents (including LMS ones)? Unless I'm missing something which is very likely.
@bhunt02 easiest way to delete all LMS chunks for a course?
There was a problem hiding this comment.
Actually wait, deleting all chunks is also a bad idea since some of the chunks are ones you would really want to keep (like custom made ones, or ones made from question, or ones that have been edited (i forget if we have an attribute for that but i don't think so)).
So maybe just deleting all chunks from uploaded documents and LMS chunk is best
Co-authored-by: Adam Fipke <adamfipke@gmail.com>
AdamFipke
left a comment
There was a problem hiding this comment.
Okay I just realised that you haven't actually requested my review just yet (idk why i thought that) and it wasn't until course-cleanup.service.ts that I realised, sorry in advance, but I did manage to find some important things (and some less important) that might help you.
| const archiveDate = new Date(); | ||
| archiveDate.setDate(15); |
There was a problem hiding this comment.
This is partially just a note for me (and @bhunt02 ) since I think our backend on production uses a different timezone so this might be an issue idk.
Maybe a fix for this is to grab the timezone from the course (course.timezone)
Co-authored-by: Adam Fipke <adamfipke@gmail.com>
Co-authored-by: Adam Fipke <adamfipke@gmail.com>
Description
This PR implements an automated course cleanup service to manage server space usage and removing course documents from ended semesters. The cronjob runs monthly (1st of the month for warnings and 15th for archival), and it sends warning emails to professors 2 weeks before archival. The archival is an automated process which cleans up associated data and archives the courses. For the sake of robustness this service will only process semesters ending after January 1, 2023.


Closes #455
Type of change
yarn installHow Has This Been Tested?
Testing the warning process by running the cron job every minute, and the archival process every two minutes. Verified the sent emails in the email log, and created test courses across various test semesters to see if the archival actually happened.
Checklist:
console.logs, leftover unused logic, or anything else that was accidentally committed)