Files
sdb2-backend/check_tasks.py
JSC dc89e45675 Refactor scheduled task repository and schemas for improved type hints and consistency
- Updated type hints from List/Optional to list/None for better readability and consistency across the codebase.
- Refactored import statements for better organization and clarity.
- Enhanced the ScheduledTaskBase schema to use modern type hints.
- Cleaned up unnecessary comments and whitespace in various files.
- Improved error handling and logging in task execution handlers.
- Updated test cases to reflect changes in type hints and ensure compatibility with the new structure.
2025-08-28 23:38:47 +02:00

53 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Check current tasks in the database."""
import asyncio
from datetime import datetime
from app.core.database import get_session_factory
from app.repositories.scheduled_task import ScheduledTaskRepository
async def check_tasks():
session_factory = get_session_factory()
async with session_factory() as session:
repo = ScheduledTaskRepository(session)
# Get all tasks
all_tasks = await repo.get_all(limit=20)
print("All tasks in database:")
print("=" * 80)
for task in all_tasks:
print(f"ID: {task.id}")
print(f"Name: {task.name}")
print(f"Type: {task.task_type}")
print(f"Status: {task.status}")
print(f"Scheduled: {task.scheduled_at}")
print(f"Timezone: {task.timezone}")
print(f"Active: {task.is_active}")
print(f"User ID: {task.user_id}")
print(f"Executions: {task.executions_count}")
print(f"Last executed: {task.last_executed_at}")
print(f"Error: {task.error_message}")
print(f"Parameters: {task.parameters}")
print("-" * 40)
# Check specifically for pending tasks
print(f"\nCurrent time: {datetime.utcnow()}")
print("\nPending tasks:")
from app.models.scheduled_task import TaskStatus
pending_tasks = await repo.get_all(limit=10)
pending_tasks = [t for t in pending_tasks if t.status == TaskStatus.PENDING and t.is_active]
if not pending_tasks:
print("No pending tasks found")
else:
for task in pending_tasks:
time_diff = task.scheduled_at - datetime.utcnow()
print(f"- {task.name} (ID: {task.id}): scheduled for {task.scheduled_at} (in {time_diff})")
if __name__ == "__main__":
asyncio.run(check_tasks())