-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_workflow.py
More file actions
60 lines (45 loc) · 1.48 KB
/
batch_workflow.py
File metadata and controls
60 lines (45 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Batch workflow: list profiles → start first N → stop all.
Env:
MULTILOGIN_BATCH_LIMIT=3 max profiles to start (default 1)
MULTILOGIN_DEMO_WAIT=5 seconds per profile
"""
import os
import sys
import time
from load_env import bootstrap_env
from multilogin_client import MultiloginClient, MultiloginError
bootstrap_env()
def main() -> None:
limit = int(os.environ.get("MULTILOGIN_BATCH_LIMIT", "1"))
wait = int(os.environ.get("MULTILOGIN_DEMO_WAIT", "5"))
try:
client = MultiloginClient()
except MultiloginError as exc:
print(f"Error: {exc}", file=sys.stderr)
sys.exit(1)
profiles = [p for p in client.list_profiles_normalized() if p.id]
if not profiles:
print("No profiles with IDs found.")
sys.exit(1)
batch = profiles[:limit]
started: list[str] = []
print(f"Batch start ({len(batch)} profiles)...")
for p in batch:
try:
session = client.start_profile_session(p.id)
started.append(p.id)
print(f" OK {p.name} cdp={session.cdp_url} port={session.debug_port}")
except MultiloginError as exc:
print(f" FAIL {p.name}: {exc}")
if started:
print(f"\nWaiting {wait}s...")
time.sleep(wait)
print("\nBatch stop...")
results = client.batch_stop(started, delay_sec=0.3)
for pid, status in results.items():
print(f" {pid}: {status}")
client.close()
print("Done.")
if __name__ == "__main__":
main()