-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add scheduling scripts for task and user inactivity
- Loading branch information
1 parent
f1f075a
commit 1275fe4
Showing
2 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Warn users and delete inactive accounts. | ||
Runs on a schedule once per week Sunday 00:00 | ||
- Warning: 21, 14, 7 days before deletion. | ||
- Deletion: 2yrs of inactivity. | ||
""" | ||
|
||
import asyncio | ||
import logging | ||
|
||
from psycopg import AsyncConnection | ||
|
||
from app.config import settings | ||
from app.users.user_crud import process_inactive_users | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
async def scheduled_process_inactive_users(): | ||
"""Process inactive users.""" | ||
try: | ||
async with await AsyncConnection.connect(settings.FMTM_DB_URL) as db: | ||
log.info("Starting processing inactive users") | ||
await process_inactive_users(db) | ||
log.info("Finished processing inactive users") | ||
except Exception as e: | ||
log.error(f"Error during processing: {e}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(scheduled_process_inactive_users()) |
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,36 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Unlock tasks with no recent activity. | ||
Runs on a schedule every three hours. | ||
- If latest event is ASSIGN, then unlock if it was three days ago. | ||
- If latest event was MAP and there has been no progress, | ||
then unlock within an three hours. | ||
""" | ||
|
||
import asyncio | ||
import logging | ||
|
||
from psycopg import AsyncConnection | ||
|
||
from app.config import settings | ||
from app.tasks.task_crud import trigger_unlock_tasks | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
log = logging.getLogger(__name__) | ||
|
||
|
||
async def scheduled_unlock_inactive_tasks(): | ||
"""Process inactive tasks.""" | ||
try: | ||
async with await AsyncConnection.connect(settings.FMTM_DB_URL) as db: | ||
log.info("Starting processing inactive tasks") | ||
await trigger_unlock_tasks(db) | ||
log.info("Finished processing inactive tasks") | ||
except Exception as e: | ||
log.error(f"Error during processing: {e}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(scheduled_unlock_inactive_tasks()) |