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
```shell
# --env dev
modal deploy --env dev cluster.rpa
modal deploy --env dev cluster.rpa_web_end_point
```

View File

@ -3,7 +3,7 @@ import hashlib
import json
import os
import time
from typing import List, Optional,Any
from typing import List, Optional, Any
import modal
from loguru import logger
@ -11,8 +11,7 @@ from playwright.async_api import async_playwright, Browser, Page
from pydantic import BaseModel
from tenacity import retry, stop_after_attempt, wait_fixed
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")
.pip_install_from_pyproject("../pyproject_rpa.toml")
@ -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)
############################ Modal app set############################
EXPLAINING: str = "讲解中"
@ -256,7 +254,7 @@ def get_job_result(call_id: str, timeout=0):
with rpa_image.imports():
@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.
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
: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}")
result = LiveStreamResult(live_id=webcast_id)
try:
@ -342,7 +341,7 @@ with rpa_image.imports():
return live_status
def submit_job(data):
def submit_job(data:LiveStreamProductWatchRequest):
call = rpa_run.spawn(data)
return call.object_id
@ -352,15 +351,16 @@ with rpa_image.imports():
logger.info("Starting local RPA test")
# 312898731614
# webcast_ids = ["36861064178"]
webcast_ids = ["36861064178"]
call_ids = [submit_job(id) for id in webcast_ids]
print("------call_ids:", call_ids)
# webcast_ids = ["36861064178"]
webcast_id = "36861064178"
# Wait for all results
for call_id in call_ids:
result = get_job_result(call_id, 8 * 60 * 60)
# result = get_job_result(call_id)
print(f"------get_job_result for {call_id}:", result)
data:LiveStreamProductWatchRequest = LiveStreamProductWatchRequest(live_id=webcast_id)
# 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)
print(f"------get_job_result for {call_id}:", result)
# @app.local_entrypoint()
# async def local_run():