Skip to content

Commit 5d6fa02

Browse files
committed
Refactor UI dump upload handling to start uploads in the background on server startup
1 parent fcdc77e commit 5d6fa02

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

node_cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from Framework.install_handler.android.java import update_java_path
3939
from settings import ZEUZ_NODE_PRIVATE_RSA_KEYS_DIR
4040
from Framework.install_handler.long_poll_handler import InstallHandler
41-
from server.mobile import upload_android_ui_dump, upload_ios_ui_dump
41+
from server.mobile import start_ui_dump_uploads
4242
from Framework.install_handler.android.android_sdk import update_android_sdk_path
4343

4444
def adjust_python_path():
@@ -1347,8 +1347,7 @@ async def main():
13471347
update_android_sdk_path()
13481348
update_outdated_modules()
13491349
asyncio.create_task(start_server())
1350-
asyncio.create_task(upload_android_ui_dump())
1351-
asyncio.create_task(upload_ios_ui_dump())
1350+
start_ui_dump_uploads()
13521351
asyncio.create_task(delete_old_automationlog_folders())
13531352
await destroy_session()
13541353

server/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from server.connect import router as connect_router
99
from server.evaluator import router as evaluator_router
1010
from server.node_operator import router as operator_router
11-
from server.mobile import router as mobile_router, upload_android_ui_dump
11+
from server.mobile import router as mobile_router, start_ui_dump_uploads
1212
from server.mac import router as mac_router
1313
from server.linux import router as linux_router
1414
from server.installers import router as installers_router
@@ -45,6 +45,10 @@ def main() -> FastAPI:
4545
v1router.include_router(linux_router)
4646
v1router.include_router(installers_router)
4747
app = FastAPI()
48+
49+
@app.on_event("startup")
50+
async def _start_background_uploads():
51+
start_ui_dump_uploads()
4852
app.include_router(v1router)
4953

5054
origins = [

server/mobile.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929

3030
router = APIRouter(prefix="/mobile", tags=["mobile"])
3131

32+
_UPLOAD_TASKS_STARTED = False
33+
34+
35+
def start_ui_dump_uploads() -> None:
36+
"""Start background UI dump uploads once per process."""
37+
global _UPLOAD_TASKS_STARTED
38+
if _UPLOAD_TASKS_STARTED:
39+
return
40+
_UPLOAD_TASKS_STARTED = True
41+
asyncio.create_task(upload_android_ui_dump())
42+
asyncio.create_task(upload_ios_ui_dump())
43+
3244

3345
def is_wda_running(port: int) -> bool:
3446
"""Check if WebDriverAgent is running on given port."""
@@ -778,4 +790,4 @@ def is_ios_app_installed(sim_udid: str, bundle_id: str):
778790

779791
return {"installed": False}
780792
except Exception as e:
781-
return {"installed": False, "error": str(e)}
793+
return {"installed": False, "error": str(e)}

0 commit comments

Comments
 (0)