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:
JSC
2025-08-28 23:38:47 +02:00
parent 96801dc4d6
commit dc89e45675
19 changed files with 292 additions and 291 deletions

View File

@@ -4,21 +4,21 @@
import asyncio
from datetime import datetime, timedelta
from app.core.database import get_session_factory
from app.main import get_global_scheduler_service
from app.models.scheduled_task import TaskType, RecurrenceType
from app.models.scheduled_task import RecurrenceType, TaskType
async def test_api_task_creation():
"""Test creating a task through the scheduler service (simulates API call)."""
try:
scheduler_service = get_global_scheduler_service()
# Create a task for 2 minutes from now
future_time = datetime.utcnow() + timedelta(minutes=2)
print(f"Creating task scheduled for: {future_time}")
print(f"Current time: {datetime.utcnow()}")
task = await scheduler_service.create_task(
name=f"API Test Task {future_time.strftime('%H:%M:%S')}",
task_type=TaskType.PLAY_SOUND,
@@ -28,13 +28,13 @@ async def test_api_task_creation():
timezone="UTC",
recurrence_type=RecurrenceType.NONE,
)
print(f"Created task: {task.name} (ID: {task.id})")
print(f"Task will execute in: {future_time - datetime.utcnow()}")
print("Task should be automatically scheduled in APScheduler!")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
asyncio.run(test_api_task_creation())
asyncio.run(test_api_task_creation())