Skip to content

Commit

Permalink
Check for running event loop & start one if nothing found
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-turner-1 committed Dec 17, 2024
1 parent 1b6f54a commit f46f554
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/access_nri_intake/data/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ async def send_telemetry(data):
f"Request failed: {e}", category=RuntimeWarning, stacklevel=2
)

# Check if there's an existing event loop, otherwise create a new one
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

# Schedule the telemetry data to be sent in the background
asyncio.create_task(send_telemetry(telemetry_data))
return None
Expand Down

0 comments on commit f46f554

Please sign in to comment.