Skip to content

Commit

Permalink
fix bureau registration loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Archento committed Nov 18, 2024
1 parent efa7816 commit 9742975
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions python/src/uagents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import (
Any,
Callable,
Coroutine,
Dict,
List,
Optional,
Expand Down Expand Up @@ -107,18 +106,6 @@ async def _run_interval(
await asyncio.sleep(period)


async def _delay(coroutine: Coroutine, delay_seconds: float):
"""
Delay the execution of the provided coroutine by the specified number of seconds.
Args:
coroutine (Coroutine): The coroutine to delay.
delay_seconds (float): The delay time in seconds.
"""
await asyncio.sleep(delay_seconds)
await coroutine


async def _send_error_message(ctx: Context, destination: str, msg: ErrorMessage):
"""
Send an error message to the specified destination.
Expand Down Expand Up @@ -1524,23 +1511,20 @@ async def _schedule_registration(self):
Start the batch registration loop.
"""

if not any(agent._endpoints for agent in self._agents):
return

time_to_next_registration = REGISTRATION_UPDATE_INTERVAL_SECONDS
try:
await self._registration_policy.register()
except InsufficientFundsError:
time_to_next_registration = 2 * AVERAGE_BLOCK_INTERVAL
except Exception as ex:
self._logger.exception(f"Failed to register: {ex}")
time_to_next_registration = REGISTRATION_RETRY_INTERVAL_SECONDS
while True:
time_to_next_registration = REGISTRATION_UPDATE_INTERVAL_SECONDS
try:
await self._registration_policy.register()
except InsufficientFundsError:
time_to_next_registration = 2 * AVERAGE_BLOCK_INTERVAL
except Exception as ex:
self._logger.exception(f"Failed to register: {ex}")
time_to_next_registration = REGISTRATION_RETRY_INTERVAL_SECONDS

# schedule the next registration update
self._loop.create_task(
_delay(self._schedule_registration(), time_to_next_registration)
)
await asyncio.sleep(time_to_next_registration)

async def run_async(self):
"""
Expand Down

0 comments on commit 9742975

Please sign in to comment.