Skip to content
This repository was archived by the owner on Mar 18, 2026. It is now read-only.

Commit 602dcfd

Browse files
add more logging
1 parent eaeb771 commit 602dcfd

1 file changed

Lines changed: 116 additions & 8 deletions

File tree

app/services/infrastructure/job_management/tasks/dao_proposal_voter.py

Lines changed: 116 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
183183
error_msg,
184184
extra={"task": "dao_proposal_voter", "message_id": message_id},
185185
)
186-
return {"success": False, "error": error_msg}
186+
return {
187+
"success": False,
188+
"error": error_msg,
189+
"error_type": "missing_proposal_id",
190+
"message_id": message_id,
191+
"wallet_id": wallet_id,
192+
"status": "failed",
193+
}
187194

188195
try:
189196
# Convert string UUID to UUID object
@@ -199,7 +206,15 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
199206
"message_id": message_id,
200207
},
201208
)
202-
return {"success": False, "error": error_msg}
209+
return {
210+
"success": False,
211+
"error": error_msg,
212+
"error_type": "invalid_proposal_id_format",
213+
"proposal_id": proposal_id,
214+
"message_id": message_id,
215+
"wallet_id": wallet_id,
216+
"status": "failed",
217+
}
203218

204219
# Get the proposal by its database ID
205220
proposal = backend.get_proposal(proposal_uuid)
@@ -209,7 +224,15 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
209224
error_msg,
210225
extra={"task": "dao_proposal_voter", "proposal_id": proposal_id},
211226
)
212-
return {"success": False, "error": error_msg}
227+
return {
228+
"success": False,
229+
"error": error_msg,
230+
"error_type": "proposal_not_found",
231+
"proposal_id": proposal_id,
232+
"message_id": message_id,
233+
"wallet_id": wallet_id,
234+
"status": "failed",
235+
}
213236

214237
# Get the wallet
215238
wallet = backend.get_wallet(wallet_id)
@@ -219,7 +242,14 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
219242
error_msg,
220243
extra={"task": "dao_proposal_voter", "wallet_id": wallet_id},
221244
)
222-
return {"success": False, "error": error_msg}
245+
return {
246+
"success": False,
247+
"error": error_msg,
248+
"error_type": "wallet_not_found",
249+
"wallet_id": wallet_id,
250+
"message_id": message_id,
251+
"status": "failed",
252+
}
223253

224254
# Get unvoted votes for this specific proposal and wallet
225255
votes = backend.list_votes(
@@ -239,6 +269,10 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
239269
"success": True,
240270
"message": "No votes to process",
241271
"votes_processed": 0,
272+
"proposal_id": proposal_id,
273+
"wallet_id": wallet_id,
274+
"message_id": message_id,
275+
"status": "completed_no_votes",
242276
}
243277
# Mark message as processed to avoid endless retries
244278
update_data = QueueMessageBase(is_processed=True, result=result)
@@ -262,6 +296,10 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
262296
"success": True,
263297
"message": "No votes to process",
264298
"votes_processed": 0,
299+
"proposal_id": proposal_id,
300+
"wallet_id": wallet_id,
301+
"message_id": message_id,
302+
"status": "completed_no_unvoted",
265303
}
266304
# Mark message as processed to avoid endless retries
267305
update_data = QueueMessageBase(is_processed=True, result=result)
@@ -288,6 +326,10 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
288326
return {
289327
"success": False,
290328
"error": error_msg,
329+
"error_type": "wallet_no_agent",
330+
"wallet_id": wallet_id,
331+
"message_id": message_id,
332+
"status": "failed",
291333
}
292334

293335
agent = backend.get_agent(wallet.agent_id)
@@ -304,6 +346,11 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
304346
return {
305347
"success": False,
306348
"error": error_msg,
349+
"error_type": "agent_not_found",
350+
"agent_id": wallet.agent_id,
351+
"wallet_id": wallet_id,
352+
"message_id": message_id,
353+
"status": "failed",
307354
}
308355

309356
if not agent.account_contract:
@@ -315,6 +362,11 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
315362
return {
316363
"success": False,
317364
"error": error_msg,
365+
"error_type": "agent_no_account_contract",
366+
"agent_id": agent.id,
367+
"wallet_id": wallet_id,
368+
"message_id": message_id,
369+
"status": "failed",
318370
}
319371

320372
# Initialize the voting tool
@@ -342,7 +394,16 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
342394
},
343395
)
344396
results.append(
345-
{"success": False, "error": error_msg, "vote_id": vote.id}
397+
{
398+
"success": False,
399+
"error": error_msg,
400+
"error_type": "vote_submission_failed",
401+
"vote_id": vote.id,
402+
"vote_answer": vote.answer,
403+
"tool_error": vote_result.get("message", "Unknown error"),
404+
"proposal_id": proposal.proposal_id,
405+
"contract_principal": proposal.contract_principal,
406+
}
346407
)
347408
continue
348409

@@ -363,8 +424,12 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
363424
{
364425
"success": False,
365426
"error": "No transaction ID found in response",
427+
"error_type": "missing_transaction_id",
366428
"vote_id": vote.id,
429+
"vote_answer": vote.answer,
367430
"vote_result": vote_result,
431+
"proposal_id": proposal.proposal_id,
432+
"contract_principal": proposal.contract_principal,
368433
}
369434
)
370435
continue
@@ -399,6 +464,10 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
399464
"success": True,
400465
"vote_id": vote.id,
401466
"tx_id": tx_id,
467+
"vote_answer": vote.answer,
468+
"proposal_id": proposal.proposal_id,
469+
"contract_principal": proposal.contract_principal,
470+
"address": address,
402471
}
403472
)
404473
else:
@@ -410,7 +479,12 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
410479
{
411480
"success": False,
412481
"error": "Failed to update vote in database",
482+
"error_type": "database_update_failed",
413483
"vote_id": vote.id,
484+
"vote_answer": vote.answer,
485+
"tx_id": tx_id,
486+
"proposal_id": proposal.proposal_id,
487+
"contract_principal": proposal.contract_principal,
414488
}
415489
)
416490
except Exception as e:
@@ -427,7 +501,13 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
427501
{
428502
"success": False,
429503
"error": f"Failed to update vote: {str(e)}",
504+
"error_type": "database_update_exception",
430505
"vote_id": vote.id,
506+
"vote_answer": vote.answer,
507+
"tx_id": tx_id,
508+
"proposal_id": proposal.proposal_id,
509+
"contract_principal": proposal.contract_principal,
510+
"exception_details": str(e),
431511
}
432512
)
433513

@@ -438,6 +518,11 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
438518
"success": True,
439519
"votes_processed": successful_votes,
440520
"votes_failed": len(results) - successful_votes,
521+
"total_votes": len(results),
522+
"proposal_id": proposal_id,
523+
"wallet_id": wallet_id,
524+
"message_id": message_id,
525+
"status": "completed_success",
441526
"results": results,
442527
}
443528
update_data = QueueMessageBase(is_processed=True, result=result)
@@ -455,8 +540,13 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
455540
"success": False,
456541
"votes_processed": successful_votes,
457542
"votes_failed": len(results) - successful_votes,
458-
"results": results,
543+
"total_votes": len(results),
544+
"proposal_id": proposal_id,
545+
"wallet_id": wallet_id,
546+
"message_id": message_id,
547+
"status": "partial_success",
459548
"message": "Partial success - some votes failed",
549+
"results": results,
460550
}
461551
update_data = QueueMessageBase(result=result)
462552
backend.update_queue_message(message_id, update_data)
@@ -474,8 +564,13 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
474564
"success": False,
475565
"votes_processed": 0,
476566
"votes_failed": len(results),
477-
"results": results,
567+
"total_votes": len(results),
568+
"proposal_id": proposal_id,
569+
"wallet_id": wallet_id,
570+
"message_id": message_id,
571+
"status": "all_failed",
478572
"message": "All votes failed",
573+
"results": results,
479574
}
480575
update_data = QueueMessageBase(result=result)
481576
backend.update_queue_message(message_id, update_data)
@@ -488,6 +583,11 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
488583
"success": True,
489584
"votes_processed": successful_votes,
490585
"votes_failed": len(results) - successful_votes,
586+
"total_votes": len(results),
587+
"proposal_id": proposal_id,
588+
"wallet_id": wallet_id,
589+
"message_id": message_id,
590+
"status": "processing_completed",
491591
"results": results,
492592
}
493593

@@ -502,7 +602,15 @@ async def _process_message(self, message: QueueMessage) -> Dict[str, Any]:
502602
},
503603
exc_info=True,
504604
)
505-
result = {"success": False, "error": error_msg}
605+
result = {
606+
"success": False,
607+
"error": error_msg,
608+
"error_type": "processing_exception",
609+
"message_id": message_id,
610+
"wallet_id": wallet_id,
611+
"status": "failed",
612+
"exception_details": str(e),
613+
}
506614

507615
# Store result even for failed processing
508616
update_data = QueueMessageBase(result=result)

0 commit comments

Comments
 (0)