#!/usr/bin/env python3 """ Landvex Grunduppbyggnad — kör massproduktion av artiklar Använder Python för bättre processhantering än bash """ 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, instance_id, cap=10): """Kör en batch med kor_agent_kimi.py""" agent_id = f"grund-{batch_id:04d}-{instance_id:02d}" cmd = [ "python3", "kor_agent_kimi.py", "--agent-id", agent_id, "--cap", str(cap) ] try: result = subprocess.run( cmd, capture_output=True, text=True, timeout=300, # 5 minuter max per batch cwd="/home/bernt/.openclaw/workspace/projects/landvex/20-automation" ) success = result.returncode == 0 if not success: log(f"✗ {agent_id} failed: {result.stderr[:200]}") return success except subprocess.TimeoutExpired: log(f"✗ {agent_id} timeout") return False except Exception as e: log(f"✗ {agent_id} error: {e}") return False def main(): log("=== LANDVEX GRUNDUPPBYGGNAD STARTAR ===") log("Mål: ~2000 artiklar på 2 timmar") log("Konfiguration: 10 parallella batcher") start_time = time.time() end_time = start_time + 7200 # 2 timmar total_articles = 0 success_count = 0 fail_count = 0 batch_num = 0 while time.time() < end_time: batch_num += 1 log(f"Runda {batch_num} startar...") round_success = 0 round_fail = 0 # Kör 10 parallella batcher with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: futures = {} for i in range(10): future = executor.submit(kor_batch, batch_num, i, 10) futures[future] = i for future in concurrent.futures.as_completed(futures): instance_id = futures[future] try: success = future.result() if success: round_success += 1 total_articles += 10 else: round_fail += 1 except Exception as e: log(f"✗ Instance {instance_id} exception: {e}") round_fail += 1 success_count += round_success fail_count += round_fail elapsed = time.time() - start_time rate = total_articles / (elapsed / 3600) if elapsed > 0 else 0 remaining = end_time - time.time() log(f"Runda {batch_num} klar. " f"Denna runda: {round_success} OK, {round_fail} fel. " f"Totalt: {total_articles} artiklar. " f"Takt: {rate:.0f} art/h. " f"Tid kvar: {remaining/60:.0f} min") # Kort paus mellan rundor time.sleep(2) total_time = time.time() - start_time log("=== GRUNDUPPBYGGNAD AVSLUTAD ===") log(f"Totalt producerade: {total_articles} artiklar") log(f"Tid: {total_time/60:.1f} minuter") log(f"Genomsnittlig takt: {total_articles/(total_time/3600):.0f} artiklar/timme") log(f"Lyckade batcher: {success_count}") log(f"Misslyckade batcher: {fail_count}") if __name__ == "__main__": try: main() except KeyboardInterrupt: log("Avbruten av användaren") sys.exit(0) except Exception as e: log(f"Kritiskt fel: {e}") sys.exit(1)