#!/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())