add worker pr

This commit is contained in:
Laura Abro
2025-04-24 12:02:50 -03:00
parent d2e5de36f3
commit a46b9345a5

View File

@ -0,0 +1,43 @@
import requests
from prometheus_test.utils import create_signature
def prepare(runner, worker):
round_state = runner.state["rounds"][str(runner.current_round)]
payload = {
"taskId": runner.config.task_id,
"action": "add-todo-pr",
"roundNumber": runner.current_round,
"prUrl": round_state["pr_urls"][worker.name],
"stakingKey": worker.staking_public_key,
"pubKey": worker.public_key,
}
return {
"signature": create_signature(worker.staking_signing_key, payload),
"stakingKey": worker.staking_public_key,
}
def execute(runner, worker, data):
"""Add worker PR URL to middle server"""
if not runner.state["pr_url"]:
print(f"✓ No PR URL found for {worker.name} - continuing")
return {"success": True, "message": "No PR URL found"}
url = f"{runner.config.middle_server_url}/summarizer/worker/add-todo-pr"
response = requests.post(
url,
json={"signature": data["signature"], "stakingKey": data["stakingKey"]},
)
result = response.json()
# Handle 409 gracefully - no eligible todos is an expected case
if response.status_code == 409:
print(
f"{result.get('message', 'No eligible todos')} for {worker.name} - continuing"
)
return {"success": True, "message": result.get("message")}
else:
response.raise_for_status()
return result