Skip to content

Commit

Permalink
more efficient task handling
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidsec committed Sep 30, 2024
1 parent c01f826 commit 7a021f9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions bbot/modules/baddns.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,19 @@ async def handle_event(self, event):
kwargs["raw_query_retry_wait"] = 0

module_instance = ModuleClass(event.data, **kwargs)
task = asyncio.create_task(module_instance.dispatch())
tasks.append((module_instance, task))

tasks.append((module_instance, asyncio.create_task(module_instance.dispatch())))
async for completed_task in self.helpers.as_completed([task for _, task in tasks]):

for module_instance, task in tasks:
module_instance = next((m for m, t in tasks if t == completed_task), None)
try:
task_result = await completed_task
except Exception as e:
self.hugewarning(f"Task for {module_instance} raised an error: {e}")
task_result = None

complete_task = await task
if complete_task:
if task_result:
results = module_instance.analyze()
if results and len(results) > 0:
for r in results:
Expand Down Expand Up @@ -122,5 +128,4 @@ async def handle_event(self, event):
tags=[f"baddns-{module_instance.name.lower()}"],
context=f'{{module}}\'s "{r_dict["module"]}" module found {{event.type}}: {{event.data}}',
)

await module_instance.cleanup()

0 comments on commit 7a021f9

Please sign in to comment.