rpa
This commit is contained in:
parent
17a283ec45
commit
094e7a9ed0
|
|
@ -273,6 +273,8 @@ with rpa_image.imports():
|
||||||
|
|
||||||
:return: Dictionary containing title, live_id, product sessions, total duration, cut commands, and error
|
:return: Dictionary containing title, live_id, product sessions, total duration, cut commands, and error
|
||||||
"""
|
"""
|
||||||
|
logger.debug(f"input data: {data}")
|
||||||
|
|
||||||
webcast_id: str = data.live_id
|
webcast_id: str = data.live_id
|
||||||
logger.info(f"Starting RPA run for webcast_id: {webcast_id}")
|
logger.info(f"Starting RPA run for webcast_id: {webcast_id}")
|
||||||
result = LiveStreamResult(live_id=webcast_id)
|
result = LiveStreamResult(live_id=webcast_id)
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,17 @@
|
||||||
|
import time
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from typing import List, Optional, Any
|
from typing import List, Optional, Any
|
||||||
|
from ulid import ULID
|
||||||
|
|
||||||
class LiveStreamProductWatchRequest(BaseModel):
|
class LiveStreamProductWatchRequest(BaseModel):
|
||||||
"""
|
"""
|
||||||
直播流商品观测
|
直播流商品观测
|
||||||
"""
|
"""
|
||||||
|
|
||||||
live_stream_name: Optional[str] = Field(None, description="直播间推流名称")
|
live_stream_name: Optional[str] = Field(str(ULID()), description="直播间推流名称约定ULID:参考https://github.com/ulid/spec")
|
||||||
"""直播间推流名称"""
|
"""直播间推流名称"""
|
||||||
live_stream_start_time: Optional[int] = 0
|
live_stream_start_time: Optional[int] = Field(int(time.time() * 1000), description="直播推流开始世界时间(毫秒时间戳)")
|
||||||
"""直播推流开始世界时间(毫秒时间戳)"""
|
"""直播推流开始世界时间(毫秒时间戳)"""
|
||||||
live_stream_url: Optional[str] = None
|
live_stream_url: Optional[str] = None
|
||||||
"""直播间推流链接"""
|
"""直播间推流链接"""
|
||||||
|
|
@ -17,6 +19,8 @@ class LiveStreamProductWatchRequest(BaseModel):
|
||||||
"""直播间id"""
|
"""直播间id"""
|
||||||
cookie_string: Optional[str] = None
|
cookie_string: Optional[str] = None
|
||||||
"""cookie string ,split('; ') """
|
"""cookie string ,split('; ') """
|
||||||
|
live_cut_url: Optional[str] = None
|
||||||
|
"""当前商品直播开始(一段时间)的截图/视频"""
|
||||||
ext_data: Optional[Any] = None
|
ext_data: Optional[Any] = None
|
||||||
"""扩展字段"""
|
"""扩展字段"""
|
||||||
|
|
||||||
|
|
@ -36,9 +40,9 @@ class ProductSession(BaseModel):
|
||||||
product_img: Optional[str] = None
|
product_img: Optional[str] = None
|
||||||
"""商品图片url"""
|
"""商品图片url"""
|
||||||
start_canvas_img: Optional[str] = None
|
start_canvas_img: Optional[str] = None
|
||||||
"""当前商品直播开始截图"""
|
"""当前商品直播开始截图/视频"""
|
||||||
end_canvas_img: Optional[str] = None
|
end_canvas_img: Optional[str] = None
|
||||||
"""当前商品直播结束截图"""
|
"""当前商品直播结束截图/视频"""
|
||||||
ext_data: Optional[Any] = None
|
ext_data: Optional[Any] = None
|
||||||
"""扩展字段"""
|
"""扩展字段"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ image = (modal.Image.debian_slim()
|
||||||
"pydantic",
|
"pydantic",
|
||||||
"scalar-fastapi>=1.0.3",
|
"scalar-fastapi>=1.0.3",
|
||||||
"loguru>=0.7.3",
|
"loguru>=0.7.3",
|
||||||
|
"python-ulid>=3.0.0",
|
||||||
])
|
])
|
||||||
.pip_install())
|
.pip_install())
|
||||||
app = modal.App("fastapi_rpa", image=image)
|
app = modal.App("fastapi_rpa", image=image)
|
||||||
|
|
@ -38,6 +39,7 @@ async def scalar_html():
|
||||||
|
|
||||||
@web_app.post("/live_watch/submit",name="直播观测提交任务",description="监测直播侧发起,观测直播商品&切条")
|
@web_app.post("/live_watch/submit",name="直播观测提交任务",description="监测直播侧发起,观测直播商品&切条")
|
||||||
async def submit_job_endpoint(data: LiveStreamProductWatchRequest) -> Optional[Any]:
|
async def submit_job_endpoint(data: LiveStreamProductWatchRequest) -> Optional[Any]:
|
||||||
|
logger.debug(f"input data: {data}")
|
||||||
process_job = modal.Function.from_name("rpa", "rpa_run")
|
process_job = modal.Function.from_name("rpa", "rpa_run")
|
||||||
|
|
||||||
call = process_job.spawn(data)
|
call = process_job.spawn(data)
|
||||||
|
|
@ -45,19 +47,17 @@ async def submit_job_endpoint(data: LiveStreamProductWatchRequest) -> Optional[A
|
||||||
|
|
||||||
|
|
||||||
@web_app.get("/live_watch/result/{call_id}",name="查询直播观测任务结果",description="异步查询")
|
@web_app.get("/live_watch/result/{call_id}",name="查询直播观测任务结果",description="异步查询")
|
||||||
async def get_job_result_endpoint(call_id: str) -> Any:
|
async def get_job_result_endpoint(call_id: str) -> Optional[LiveStreamResult]:
|
||||||
|
logger.debug(f"input call_id: {call_id}")
|
||||||
|
|
||||||
function_call = modal.FunctionCall.from_id(call_id)
|
function_call = modal.FunctionCall.from_id(call_id)
|
||||||
try:
|
try:
|
||||||
result = function_call.get(timeout=0)
|
result = function_call.get(timeout=0)
|
||||||
except modal.exception.OutputExpiredError:
|
except BaseException as e:
|
||||||
return fastapi.responses.JSONResponse(content="", status_code=404)
|
logger.error(f"Exception: {e}")
|
||||||
except TimeoutError:
|
return None
|
||||||
return fastapi.responses.JSONResponse(content="", status_code=202)
|
|
||||||
|
|
||||||
logger.debug("res:",result)
|
logger.debug("res:",result)
|
||||||
if len(result) == 0:
|
|
||||||
return fastapi.responses.JSONResponse(content=LIVE_WATCH_TASK_DOING, status_code=200)
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# modal serve my_job_queue_endpoint.py
|
# modal serve my_job_queue_endpoint.py
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue