Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions commands/update_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,23 @@ async def update_stats(ctx: Context, *options):
if opt.username:
update_players.extend(opt.username)

async with grpc.aio.insecure_channel("localhost:50051") as channel:
stub = player_stats_update_pb2_grpc.PlayerStatsUpdaterStub(channel)
start = time.time()
response = await stub.UpdatePlayerStats(player_stats_update_pb2.Request(player_uuid=update_players))
end = time.time()
# Validate that we have players to update
if not update_players:
return await LongTextEmbed.send_message(valor, ctx, title=f"Player Stats Update",
content="No players found to update.", color=0xFF0000)
#proper error handling hopefully stops the command from crashing
try:
async with grpc.aio.insecure_channel("localhost:50051") as channel:
stub = player_stats_update_pb2_grpc.PlayerStatsUpdaterStub(channel)
start = time.time()
response = await stub.UpdatePlayerStats(player_stats_update_pb2.Request(player_uuid=update_players))
end = time.time()
except grpc.RpcError as e:
return await LongTextEmbed.send_message(valor, ctx, title=f"Player Stats Update Error",
content=f"gRPC connection failed: {e.code()}: {e.details()}", color=0xFF0000)
except Exception as e:
return await LongTextEmbed.send_message(valor, ctx, title=f"Player Stats Update Error",
content=f"Unexpected error during update: {str(e)}", color=0xFF0000)

requested_players = set(update_players)
failed_players = set(response.failures)
Expand All @@ -88,4 +100,4 @@ async def update_stats(ctx: Context):
await LongTextEmbed.send_message(valor, ctx, "Update stats command", desc, color=0xFF00)