From d2e5de36f3a8328a71ed3f44e5c46c8b6f94d159 Mon Sep 17 00:00:00 2001 From: Laura Abro Date: Thu, 24 Apr 2025 11:58:14 -0300 Subject: [PATCH] add worker task --- worker/orca-agent/tests/stages/worker_task.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/worker/orca-agent/tests/stages/worker_task.py b/worker/orca-agent/tests/stages/worker_task.py index e69de29..5ff830d 100644 --- a/worker/orca-agent/tests/stages/worker_task.py +++ b/worker/orca-agent/tests/stages/worker_task.py @@ -0,0 +1,60 @@ +"""Stage for executing worker tasks.""" + +import requests + + +def prepare(runner, worker): + """Prepare data for worker task""" + + return { + "taskId": runner.config.task_id, + "round_number": str(runner.current_round), + "repo_url": runner.state["repo_url"], + } + + +def execute(runner, worker, data): + """Execute worker task step""" + if not runner.state["repo_url"]: + print(f"✓ No repo url found for {worker.name} - continuing") + return {"success": True, "message": "No repo url found"} + + url = f"{worker.url}/worker-task/{data['roundNumber']}" + response = requests.post(url, json=data) + result = response.json() + + # Handle 409 gracefully - no eligible todos is an expected case + if response.status_code in [401, 409]: + print( + f"✓ {result.get('message', 'No eligible todos')} for {worker.name} - continuing" + ) + return {"success": True, "message": result.get("message")} + + if result.get("success") and "pr_url" in result: + round_key = str(runner.current_round) + round_state = runner.state["rounds"].setdefault(round_key, {}) + + # Initialize pr_urls if not exists + if "pr_urls" not in round_state: + round_state["pr_urls"] = {} + round_state["pr_urls"][worker.name] = result["pr_url"] + + # Initialize submission_data if not exists + # if "submission_data" not in round_state: + # round_state["submission_data"] = {} + + # Store submission data + # round_state["submission_data"][worker.name] = { + # "githubUsername": worker.env.get("GITHUB_USERNAME"), + # "nodeType": "worker", + # "prUrl": result["pr_url"], + # "repoName": result.get("repoName"), + # "repoOwner": result.get("repoOwner"), + # "roundNumber": runner.current_round, + # "taskId": runner.config.task_id, + # "uuid": result.get("uuid"), # Should be provided by the worker + # "stakingKey": worker.staking_public_key, + # "pubKey": worker.public_key, + # } + + return result