Files
boc/projects/landvex/20-automation/batch_runner.py
T

72 lines
2.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
Landvex Batch Runner — kör massproduktion av artiklar
"""
import subprocess
import concurrent.futures
import time
import sys
from datetime import datetime, timezone
def log(msg):
ts = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC")
print(f"[{ts}] {msg}", flush=True)
def kor_batch(batch_id, cap=10):
"""Kör en batch med kor_agent_kimi.py"""
agent_id = f"batch-{batch_id:04d}"
cmd = f"cd /home/bernt/.openclaw/workspace/projects/landvex/20-automation && python3 kor_agent_kimi.py --agent-id {agent_id} --cap {cap}"
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
return result.returncode == 0
def main():
log("=== LANDVEX GRUNDUPPBYGGNAD STARTAR ===")
log("Mål: 2000 artiklar på 2 timmar")
log("Konfiguration: 10 parallella batcher × 100 artiklar")
start_time = time.time()
total_batches = 20 # 20 batcher × 100 artiklar = 2000
batch_size = 100
max_workers = 10
completed = 0
failed = 0
for round_num in range(2): # 2 rundor × 10 batcher
log(f"Runda {round_num + 1}/2 startar...")
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = {}
for i in range(max_workers):
batch_id = round_num * max_workers + i
future = executor.submit(kor_batch, batch_id, batch_size)
futures[future] = batch_id
for future in concurrent.futures.as_completed(futures):
batch_id = futures[future]
try:
success = future.result()
if success:
completed += 1
log(f"✓ Batch {batch_id} klar")
else:
failed += 1
log(f"✗ Batch {batch_id} misslyckades")
except Exception as e:
failed += 1
log(f"✗ Batch {batch_id} fel: {e}")
elapsed = time.time() - start_time
rate = (completed * batch_size) / (elapsed / 3600) if elapsed > 0 else 0
log(f"Runda {round_num + 1} klar. Tid: {elapsed/60:.1f} min. Takt: {rate:.0f} art/h")
total_time = time.time() - start_time
log("=== GRUNDUPPBYGGNAD AVSLUTAD ===")
log(f"Totalt: {completed * batch_size} artiklar på {total_time/60:.1f} minuter")
log(f"Genomsnittlig takt: {completed * batch_size / (total_time/3600):.0f} artiklar/timme")
log(f"Misslyckade batcher: {failed}")
if __name__ == "__main__":
main()