Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) add update bots on loop #32

Merged
merged 1 commit into from
Aug 30, 2024
Merged
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
47 changes: 24 additions & 23 deletions services/bots_orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,30 @@ def stop_update_active_bots_loop(self):
self._update_bots_task.cancel()
self._update_bots_task = None

async def update_active_bots(self, sleep_time=10):
active_hbot_containers = self.get_active_containers()
# Remove bots that are no longer active
for bot in list(self.active_bots):
if bot not in active_hbot_containers:
del self.active_bots[bot]

# Add new bots or update existing ones
for bot in active_hbot_containers:
if bot not in self.active_bots:
hbot_listener = HummingbotPerformanceListener(host=self.broker_host, port=self.broker_port,
username=self.broker_username,
password=self.broker_password,
bot_id=bot)
hbot_listener.start()
self.active_bots[bot] = {
"bot_name": bot,
"broker_client": BotCommands(host=self.broker_host, port=self.broker_port,
username=self.broker_username, password=self.broker_password,
bot_id=bot),
"broker_listener": hbot_listener,
}
await asyncio.sleep(sleep_time)
async def update_active_bots(self, sleep_time=1):
while True:
active_hbot_containers = self.get_active_containers()
# Remove bots that are no longer active
for bot in list(self.active_bots):
if bot not in active_hbot_containers:
del self.active_bots[bot]

# Add new bots or update existing ones
for bot in active_hbot_containers:
if bot not in self.active_bots:
hbot_listener = HummingbotPerformanceListener(host=self.broker_host, port=self.broker_port,
username=self.broker_username,
password=self.broker_password,
bot_id=bot)
hbot_listener.start()
self.active_bots[bot] = {
"bot_name": bot,
"broker_client": BotCommands(host=self.broker_host, port=self.broker_port,
username=self.broker_username, password=self.broker_password,
bot_id=bot),
"broker_listener": hbot_listener,
}
await asyncio.sleep(sleep_time)

# Interact with a specific bot
def start_bot(self, bot_name, **kwargs):
Expand Down