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.
This commit is contained in:
@@ -7,15 +7,16 @@ 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:
|
||||
@@ -32,14 +33,14 @@ async def check_tasks():
|
||||
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:
|
||||
@@ -48,4 +49,4 @@ async def check_tasks():
|
||||
print(f"- {task.name} (ID: {task.id}): scheduled for {task.scheduled_at} (in {time_diff})")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(check_tasks())
|
||||
asyncio.run(check_tasks())
|
||||
|
||||
Reference in New Issue
Block a user