Skip to content

Commit

Permalink
feat: add scheduling scripts for task and user inactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Feb 5, 2025
1 parent f1f075a commit 1275fe4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/backend/scheduler/inactive_users.py
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())
36 changes: 36 additions & 0 deletions src/backend/scheduler/unlock_tasks.py
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())

0 comments on commit 1275fe4

Please sign in to comment.