Skip to content

Commit

Permalink
fix(ingest/okta): Conditionally close event_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
maiarareinaldo committed Aug 24, 2023
1 parent 77ba391 commit dcd9e0f
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,13 @@ def get_workunits_internal(self) -> Iterable[MetadataWorkUnit]:
# This method can be called on the main thread or an async thread, so we must create a new loop if one doesn't exist
# See https://docs.python.org/3/library/asyncio-eventloop.html for more info.

created_event_loop = False
try:
event_loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
except RuntimeError:
event_loop = asyncio.new_event_loop()
asyncio.set_event_loop(event_loop)
created_event_loop = True

# Step 1: Produce MetadataWorkUnits for CorpGroups.
okta_groups: Optional[Iterable[Group]] = None
Expand Down Expand Up @@ -408,7 +410,8 @@ def get_workunits_internal(self) -> Iterable[MetadataWorkUnit]:
).as_workunit()

# Step 4: Close the event loop
event_loop.close()
if created_event_loop:
event_loop.close()

def get_report(self):
return self.report
Expand Down

0 comments on commit dcd9e0f

Please sign in to comment.