Skip to content

Commit

Permalink
Test background tasks (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
avgupta456 authored Nov 19, 2023
1 parent 97df594 commit 892fafd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion backend/src/subscriber/routers/dev.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from datetime import date, timedelta
from typing import Any, Dict, Optional

from fastapi import APIRouter, Response, status
import asyncio
from fastapi import APIRouter, BackgroundTasks, Response, status

from src.data.mongo.secret import update_keys
from src.models import UserPackage, WrappedPackage
Expand Down Expand Up @@ -47,3 +48,16 @@ async def get_wrapped_user_raw(
user_id, date(year, 1, 1), date(year, 12, 31), "US/Eastern", access_token
)
return get_wrapped_data(user_data, year)


async def print_task(start_str: str, end_str: str):
print(start_str)
await asyncio.sleep(10)
print(end_str)


@router.get("/test", status_code=status.HTTP_200_OK, response_model=Dict[str, Any])
@async_fail_gracefully
async def test(response: Response, background_tasks: BackgroundTasks) -> str:
background_tasks.add_task(print_task, "start", "end")
return "Test"

0 comments on commit 892fafd

Please sign in to comment.