From b13cb72219faa6533e212fcf9539b2fdaccb3acd Mon Sep 17 00:00:00 2001 From: zjf Date: Mon, 26 May 2025 17:13:39 +0800 Subject: [PATCH] rpa --- src/cluster/rpa.md | 2 ++ src/cluster/rpa.py | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/cluster/rpa.md b/src/cluster/rpa.md index c974ce1..5fd61df 100644 --- a/src/cluster/rpa.md +++ b/src/cluster/rpa.md @@ -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 ``` \ No newline at end of file diff --git a/src/cluster/rpa.py b/src/cluster/rpa.py index b3f1aa0..0128350 100644 --- a/src/cluster/rpa.py +++ b/src/cluster/rpa.py @@ -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():