[Feature:System] Cleanup stale active_graders locks#12427
Conversation
Closes Submitty#11557 Creates sbin/cleanup_active_graders.py that iterates through all course databases and removes active_graders rows older than 48 hours. These stale entries are leftover locks from graders who closed their browser without saving.
JManion32
left a comment
There was a problem hiding this comment.
Hello @srikaaviya, thank you for your contribution, this is great work! Please be sure to follow our title guidelines (prefix and 40 chars, see more here) use the provided description template:
### Why is this Change Important & Necessary?
<!-- Include any GitHub issue that is fixed/closed using "Fixes #<number>" or "Closes #<number>" syntax.
Alternately write "Partially addresses #<number>" or "Related to #<number>" as appropriate. -->
### What is the New Behavior?
<!-- Include before & after screenshots/videos if the user interface has changed. -->
### What steps should a reviewer take to reproduce or test the bug or new feature?
### Automated Testing & Documentation
<!-- Is this feature sufficiently tested by unit tests and end-to-end tests?
If this PR does not add/update the necessary automated tests, write a new GitHub issue and link it below.
Is this feature sufficiently documented on submitty.org?
Link related PRs or new GitHub issue to update documentation. -->
### Other information
<!-- Is this a breaking change?
Does this PR include migrations to update existing installations?
Are there security concerns with this PR? -->
Overall, the approach for this script is logical, but I do think we should reuse setup_db if possible.
Do you have a follow-up in mind for this PR that will add the script to a cron job, or installation script? You could also add it here. I'm just worried that if we merge this as-is, it may be forgotten before we can automate it.
| # 3. Construct Course DB Connection String | ||
| db_name = f"submitty_{term}_{course}" | ||
|
|
||
| # Logic adapted from database_queries.setup_db |
There was a problem hiding this comment.
Why duplicate the logic instead of reusing it here?
There was a problem hiding this comment.
I duplicated the connection logic because setup_db() was only connect to the 'submitty' database, and I wasn't sure if modifying an existing function was acceptable. I'll refactor setup_db() to accept an optional db_name, so it can be reused here.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12427 +/- ##
=========================================
Coverage 21.50% 21.50%
Complexity 9896 9896
=========================================
Files 268 268
Lines 36968 36968
Branches 495 495
=========================================
Hits 7951 7951
Misses 28526 28526
Partials 491 491
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
@JManion32 Thank you for the review! I'll update the PR title and description to follow the project guidelines, and I'll fix the CI Python lint error.
I feel like adding it to the crontab would be better since we have that structure already. |
|
Hi @JManion32 , I've addressed all the feedback from your review (fixed the cron job placement and Python lint issues). Would you be able to take another look when you have a moment? Thanks! |
roye2
left a comment
There was a problem hiding this comment.
I reviewed the code and it looks like you followed through with the changes requested by Justin. Please fix the Python linting errors.
|
@srikaaviya Python linting is still failing. |
Fixed listing errors |
There was a problem hiding this comment.
@roye2 @GarvitKhandelwal31 Pylint errors seem to have been fixed. All courses passed through the script, and cleanup_active_graders.py ran successfully across all courses in my local environment. Ready to merge.
bmcutler
left a comment
There was a problem hiding this comment.
Approving now that I've properly fixed the pylint errors (we should not just comment out the lint testing if a proper fix is practical) and added a transation commit statement the PR actually works. I'm curious if the original author fully tested this PR? I'm not sure it worked before.
It actually worked for me during local testing, likely because my local db was defaulting to auto-commit, so I completely missed that. Thank you for taking the time to fix and get it merged! |
### Why is this Change Important & Necessary? Closes Submitty#11557 In some cases, if a grader closes their web browser with a tab open on a particular student, we will not detect that the grader is no longer actively working and the `active_graders` row is never cleaned up. Over time, these stale entries may accumulate and clutter the grading status dashboard. ### What is the New Behavior? Adds [sbin/cleanup_active_graders.py] — a maintenance script that: 1. Connects to the master database to get all active courses. 2. Iterates through each course database (`submitty_{term}_{course}`). 3. Deletes `active_graders` rows older than 24 hours. The script reuses the existing `setup_db()` helper from [database_queries.py] to avoid duplicating database connection logic. It is scheduled to run daily at 3AM via the Submitty cron job ([.setup/submitty_crontab]. ### What steps should a reviewer take to reproduce or test the bug or new feature? 1. In a course database, manually insert a stale row into `active_graders` with a timestamp older than 48 hours. 2. Run `python3 /usr/local/submitty/sbin/cleanup_active_graders.py`. 3. Confirm the stale row is deleted and recent rows are preserved. ### Automated Testing & Documentation No automated tests added. The script logic is a straightforward parameterized DELETE query filtered by timestamp across all course databases. ### Other information No breaking changes or migrations. The script only performs a targeted DELETE. The cron entry and daemon permissions are set up as part of the standard Submitty installation process. --------- Co-authored-by: Emma Roy <[email protected]> Co-authored-by: Garvit Khandelwal <[email protected]> Co-authored-by: Barb Cutler <[email protected]> Co-authored-by: Barb Cutler <Barb Cutler>
Why is this Change Important & Necessary?
Closes #11557
In some cases, if a grader closes their web browser with a tab open on a particular student, we will not detect that the grader is no longer actively working and the
active_gradersrow is never cleaned up. Over time, these stale entries may accumulate and clutter the grading status dashboard.What is the New Behavior?
Adds [sbin/cleanup_active_graders.py] — a maintenance script that:
submitty_{term}_{course}).active_gradersrows older than 24 hours.The script reuses the existing
setup_db()helper from[database_queries.py] to avoid duplicating database connection logic.
It is scheduled to run daily at 3AM via the Submitty cron job
([.setup/submitty_crontab].
What steps should a reviewer take to reproduce or test the bug or new feature?
active_graderswith a timestamp older than 48 hours.python3 /usr/local/submitty/sbin/cleanup_active_graders.py.Automated Testing & Documentation
No automated tests added. The script logic is a straightforward
parameterized DELETE query filtered by timestamp across all course
databases.
Other information
No breaking changes or migrations. The script only performs a
targeted DELETE. The cron entry and daemon permissions are set up
as part of the standard Submitty installation process.