DrewTCurrie / 55ATAT

Senior Design Team 55 at MSU
0 stars 0 forks source link

Garbage collector/dev #45

Closed DrewTCurrie closed 1 week ago

DrewTCurrie commented 1 week ago

Created a garbage collector to clear out old reports, badges, and profile pictures. This required a rewrite of the background task scheduler that previously existed for automatic report generation. This is because the new system would use different pathing to access the files to be removed and to handle multiple threads.

Once the background scheduler is called, it checks if today is the last day of the week or the last day of the month and then decides what to do. Previously it was hardcoded that if it was the last day of the week to only generate a weekly report and similarly for the monthly reports.

Scheduler checks:

def CheckEndOfWeek():
    print("Checking if today is the last day of the week.")
    today = datetime.today()
    if date.today().weekday() == 4:
        print("Today is the last day of the week.")
        return(True)
    else:
        print("Today is not the last day of the week.")
        return(False)

def CheckEndOfMonth():
    today = datetime.today()
    print("Checking if today is the last day of the month.")
    if calendar.monthrange(today.year, today.month)[1] == today.day:
        print("Today is the last day of the month.")
        return(True)
    else:
        print("Today is not the last day of the month.")
        return(False)

In the backgroundScheduler.py file new tasks can be easily added to run on a weekly or monthly basis:

def MonthlyTasks(app, mail):
    #If it is the last day of the month, generate monthly attendance report
    reportScheduler.monthly_reports(app, mail)
    time.sleep(60)
    #Delete archival records then move current records into archive
    #Archive records and then delete records from current attedance event table
    #This resets the database in prepartion for the new month
    print("Clearing archival attendance records")
    utils.ClearArchivalAttendanceRecords()
    print("archiving current month's records")
    utils.ArchiveAttedanceRecords()
    print("Clearning current month's records")
    utils.ClearAttendanceRecords()
    #Run garbage collector on everything
    print("Running garbage collector")
    garbagecollector.CollectGarbage()

Adding new functions to the monthly or weekly tasks list will cause those tasks to be executed at 9:00PM local time on the respective trigger date.

This is fully integrated in with the automatic mailing of the reports and closes out:

19 #20 & #34

DrewTCurrie commented 1 week ago

Need to pull dev back into this and edit it to remove old audio files and set all messages/audio back to default. Waiting on resolution of #46

DrewTCurrie commented 1 week ago

The timing of some of the commits also seems to be off from when I was testing the garbage collector running automatically on 10/31/2024. This shouldn't cause an issue but it does mess with the git history. Thought I had this fixed but I guess not.

DrewTCurrie commented 1 week ago

Tested with audio changes. This works, but does not set everything back to default.