diff --git a/worker/orca-agent/src/database/models.py b/worker/orca-agent/src/database/models.py index 7a83ad5..75bb54e 100644 --- a/worker/orca-agent/src/database/models.py +++ b/worker/orca-agent/src/database/models.py @@ -10,7 +10,7 @@ class Submission(SQLModel, table=True): """Task submission model.""" task_id: str - round_number: int = Field(primary_key=True) + swarmBountyId: int = Field(primary_key=True) status: str = "pending" pr_url: Optional[str] = None username: Optional[str] = None diff --git a/worker/orca-agent/src/server/routes/submission.py b/worker/orca-agent/src/server/routes/submission.py index dcaeb66..5ffcab7 100644 --- a/worker/orca-agent/src/server/routes/submission.py +++ b/worker/orca-agent/src/server/routes/submission.py @@ -9,14 +9,14 @@ logger = logging.getLogger(__name__) bp = Blueprint("submission", __name__) -@bp.get("/submission/") -def fetch_submission(roundNumber): - logger.info(f"Fetching submission for round: {roundNumber}") +@bp.get("/submission/") +def fetch_submission(swarmBountyId): + logger.info(f"Fetching submission for swarmBountyId: {swarmBountyId}") db = get_db() submission = ( db.query(Submission) .filter( - Submission.round_number == int(roundNumber), + Submission.swarmBountyId == int(swarmBountyId), ) .first() ) @@ -28,7 +28,7 @@ def fetch_submission(roundNumber): return jsonify( { "taskId": submission.task_id, - "roundNumber": submission.round_number, + "swarmBountyId": submission.swarmBountyId, "status": submission.status, "prUrl": submission.pr_url, "githubUsername": github_username, diff --git a/worker/orca-agent/src/server/routes/task.py b/worker/orca-agent/src/server/routes/task.py index 417d662..d5ab6e8 100644 --- a/worker/orca-agent/src/server/routes/task.py +++ b/worker/orca-agent/src/server/routes/task.py @@ -10,7 +10,7 @@ bp = Blueprint("task", __name__) executor = ThreadPoolExecutor(max_workers=2) -def post_pr_url(agent_result, task_id, signature, round_number): +def post_pr_url(agent_result, task_id, signature, swarmBountyId): try: result = agent_result.result() # Get the result from the future logger.info(f"Result: {result}") @@ -22,7 +22,7 @@ def post_pr_url(agent_result, task_id, signature, round_number): json={ "prUrl": result_data.get("data", {}).get("pr_url"), "signature": signature, - "roundNumber": round_number, + "swarmBountyId": swarmBountyId, "success": result.get("success", False), "message": result_data.get("error", ""), }, @@ -38,17 +38,18 @@ def post_pr_url(agent_result, task_id, signature, round_number): logger.error(f"Traceback: {''.join(traceback.format_tb(e.__traceback__))}") -@bp.post("/worker-task/") -def start_task(round_number): +@bp.post("/worker-task") +def start_task(): logger = repo_summary_service.logger - logger.info(f"Task started for round: {round_number}") + # logger.info(f"Task started for bounty: {swarmBountyId}") data = request.get_json() task_id = data["task_id"] podcall_signature = data["podcall_signature"] repo_url = data["repo_url"] + swarmBountyId = data["swarmBountyId"] logger.info(f"Task data: {data}") - required_fields = ["task_id", "round_number", "repo_url", "podcall_signature"] + required_fields = ["task_id", "swarmBountyId", "repo_url", "podcall_signature"] if any(data.get(field) is None for field in required_fields): return jsonify({"error": "Missing data"}), 401 @@ -58,7 +59,7 @@ def start_task(round_number): if os.getenv("TEST_MODE") == "true": result = repo_summary_service.handle_task_creation( task_id=task_id, - round_number=int(round_number), + swarmBountyId=swarmBountyId, repo_url=repo_url, db=db, # Pass db instance ) @@ -67,12 +68,12 @@ def start_task(round_number): agent_result = executor.submit( repo_summary_service.handle_task_creation, task_id=task_id, - round_number=round_number, + swarmBountyId=swarmBountyId, repo_url=repo_url, db=db, # Pass db instance ) agent_result.add_done_callback( - lambda future: post_pr_url(future, task_id, podcall_signature, round_number) + lambda future: post_pr_url(future, task_id, podcall_signature, swarmBountyId) ) return jsonify({"status": "Task is being processed"}), 200 @@ -87,14 +88,14 @@ if __name__ == "__main__": # Test data test_data = { "taskId": "fake", - "round_number": "1", + "swarmBountyId": "1", "repo_url": "https://github.com/koii-network/docs", } # Set up test context with app.test_client() as client: # Make a POST request to the endpoint - response = client.post("/repo_summary/1", json=test_data) + response = client.post("/worker-task", json=test_data) # Print the response print(f"Status Code: {response.status_code}") diff --git a/worker/orca-agent/src/server/services/repo_summary_service.py b/worker/orca-agent/src/server/services/repo_summary_service.py index 4b12c9a..5b0e4b1 100644 --- a/worker/orca-agent/src/server/services/repo_summary_service.py +++ b/worker/orca-agent/src/server/services/repo_summary_service.py @@ -11,7 +11,7 @@ from src.database.models import Submission load_dotenv() -def handle_task_creation(task_id, round_number, repo_url, db=None): +def handle_task_creation(task_id, swarmBountyId, repo_url, db=None): """Handle task creation request.""" try: if db is None: @@ -28,7 +28,7 @@ def handle_task_creation(task_id, round_number, repo_url, db=None): if result.get("success"): submission = Submission( task_id=task_id, - round_number=round_number, + swarmBountyId=swarmBountyId, status="summarized", repo_url=repo_url, pr_url=result["data"]["pr_url"], @@ -50,7 +50,7 @@ if __name__ == "__main__": with app.app_context(): result = handle_task_creation( task_id="1", - round_number=6, + swarmBountyId=1, repo_url="https://github.com/koii-network/builder-test", ) print(result)