This commit is contained in:
zjf 2025-05-26 17:13:39 +08:00
parent 48adb98969
commit b13cb72219
2 changed files with 16 additions and 14 deletions

View File

@ -5,5 +5,7 @@ python -m modal setup
deploy by env deploy by env
```shell ```shell
# --env dev
modal deploy --env dev cluster.rpa modal deploy --env dev cluster.rpa
modal deploy --env dev cluster.rpa_web_end_point
``` ```

View File

@ -13,7 +13,6 @@ from tenacity import retry, stop_after_attempt, wait_fixed
from ulid import ULID from ulid import ULID
from .rpa_comm import LiveStreamProductWatchRequest, LiveStreamResult, ProductSession from .rpa_comm import LiveStreamProductWatchRequest, LiveStreamResult, ProductSession
rpa_image = (modal.Image.debian_slim(python_version="3.11") rpa_image = (modal.Image.debian_slim(python_version="3.11")
.pip_install_from_pyproject("../pyproject_rpa.toml") .pip_install_from_pyproject("../pyproject_rpa.toml")
.env({"PLAYWRIGHT_BROWSERS_PATH": "/root/browsers"}) .env({"PLAYWRIGHT_BROWSERS_PATH": "/root/browsers"})
@ -24,7 +23,6 @@ rpa_image = (modal.Image.debian_slim(python_version="3.11")
) )
app = modal.App(name='rpa', image=rpa_image, include_source=False) app = modal.App(name='rpa', image=rpa_image, include_source=False)
############################ Modal app set############################ ############################ Modal app set############################
EXPLAINING: str = "讲解中" EXPLAINING: str = "讲解中"
@ -256,7 +254,7 @@ def get_job_result(call_id: str, timeout=0):
with rpa_image.imports(): with rpa_image.imports():
@app.function(timeout=8 * 60 * 60) @app.function(timeout=8 * 60 * 60)
async def rpa_run(webcast_id: str) -> dict: async def rpa_run(data: LiveStreamProductWatchRequest) -> dict:
""" """
Records product sessions for all products in a Douyin live session. Records product sessions for all products in a Douyin live session.
Includes product name, ID, and generates FFmpeg cut commands. Includes product name, ID, and generates FFmpeg cut commands.
@ -266,6 +264,7 @@ with rpa_image.imports():
:param webcast_id: The ID of the live stream :param webcast_id: The ID of the live stream
: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
""" """
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)
try: try:
@ -342,7 +341,7 @@ with rpa_image.imports():
return live_status return live_status
def submit_job(data): def submit_job(data:LiveStreamProductWatchRequest):
call = rpa_run.spawn(data) call = rpa_run.spawn(data)
return call.object_id return call.object_id
@ -352,12 +351,13 @@ with rpa_image.imports():
logger.info("Starting local RPA test") logger.info("Starting local RPA test")
# 312898731614 # 312898731614
# webcast_ids = ["36861064178"] # webcast_ids = ["36861064178"]
webcast_ids = ["36861064178"] # webcast_ids = ["36861064178"]
call_ids = [submit_job(id) for id in webcast_ids] webcast_id = "36861064178"
print("------call_ids:", call_ids)
# Wait for all results data:LiveStreamProductWatchRequest = LiveStreamProductWatchRequest(live_id=webcast_id)
for call_id in call_ids: # TODO other info
call_id = submit_job(data)
print("------call_id:", call_id)
result = get_job_result(call_id, 8 * 60 * 60) result = get_job_result(call_id, 8 * 60 * 60)
# result = get_job_result(call_id) # result = get_job_result(call_id)
print(f"------get_job_result for {call_id}:", result) print(f"------get_job_result for {call_id}:", result)