koenverhagen commited on
Commit
ffce8b3
1 Parent(s): 5a6ca0c

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +5 -4
server.py CHANGED
@@ -1,7 +1,7 @@
1
  import asyncio
2
  from concurrent.futures import ThreadPoolExecutor
3
 
4
- from fastapi import FastAPI, Response, Request
5
  from starlette.middleware.cors import CORSMiddleware
6
  # import json
7
  # from load_data import get_design_data, get_design_resolutions_for_shop
@@ -50,12 +50,13 @@ async def root():
50
 
51
 
52
  @app.post("/lal_for_shop")
53
- async def submit_async_task(request: Request, response: Response, shop: Shop):
54
- loop = asyncio.new_event_loop()
55
  authorization_token = request.headers.get("Authorization", None)
56
  check_token = check_auth(authorization_token)
57
  if check_token:
58
- task = asyncio.create_task(create_feature_files(shop))
 
59
  return {"message": f"shop calculation for shop {shop.id} submitted"}
60
  else:
61
  print(authorization_token)
 
1
  import asyncio
2
  from concurrent.futures import ThreadPoolExecutor
3
 
4
+ from fastapi import FastAPI, Response, Request, BackgroundTasks
5
  from starlette.middleware.cors import CORSMiddleware
6
  # import json
7
  # from load_data import get_design_data, get_design_resolutions_for_shop
 
50
 
51
 
52
  @app.post("/lal_for_shop")
53
+ async def submit_async_task(request: Request, response: Response,background_tasks: BackgroundTasks, shop: Shop):
54
+ # loop = asyncio.new_event_loop()
55
  authorization_token = request.headers.get("Authorization", None)
56
  check_token = check_auth(authorization_token)
57
  if check_token:
58
+ # task = asyncio.create_task(create_feature_files(shop))
59
+ background_tasks.add_task(create_feature_files, shop)
60
  return {"message": f"shop calculation for shop {shop.id} submitted"}
61
  else:
62
  print(authorization_token)