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:
@@ -5,18 +5,19 @@ import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from app.core.database import get_session_factory
|
||||
from app.models.scheduled_task import RecurrenceType, TaskType
|
||||
from app.repositories.scheduled_task import ScheduledTaskRepository
|
||||
from app.models.scheduled_task import TaskType, RecurrenceType
|
||||
|
||||
|
||||
async def create_future_task():
|
||||
session_factory = get_session_factory()
|
||||
|
||||
|
||||
# Create a task for 2 minutes from now
|
||||
future_time = datetime.utcnow() + timedelta(minutes=2)
|
||||
|
||||
|
||||
async with session_factory() as session:
|
||||
repo = ScheduledTaskRepository(session)
|
||||
|
||||
|
||||
task_data = {
|
||||
"name": f"Future Task {future_time.strftime('%H:%M:%S')}",
|
||||
"task_type": TaskType.PLAY_SOUND,
|
||||
@@ -26,11 +27,11 @@ async def create_future_task():
|
||||
"user_id": 1,
|
||||
"recurrence_type": RecurrenceType.NONE,
|
||||
}
|
||||
|
||||
|
||||
task = await repo.create(task_data)
|
||||
print(f"Created task: {task.name} (ID: {task.id}) scheduled for {task.scheduled_at}")
|
||||
print(f"Current time: {datetime.utcnow()}")
|
||||
print(f"Task will execute in: {future_time - datetime.utcnow()}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(create_future_task())
|
||||
asyncio.run(create_future_task())
|
||||
|
||||
Reference in New Issue
Block a user