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

Make sure Lock object is initialized in the same event loop #241

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions datadog_sync/utils/base_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class ResourceConfig:
tagging_config: Optional[TaggingConfig] = None
async_lock: Optional[Lock] = None

async def init_async(self) -> None:
self.async_lock = Lock()

def __post_init__(self) -> None:
self.build_excluded_attributes()
if not self.concurrent:
Expand All @@ -84,6 +87,9 @@ def __init__(self, config: Configuration) -> None:
self.resource_type
)

async def init_async(self):
await self.resource_config.init_async()

@abc.abstractmethod
async def get_resources(self, client: CustomClient) -> List[Dict]:
pass
Expand Down
2 changes: 2 additions & 0 deletions datadog_sync/utils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Configuration(object):
async def init_async(self, cmd: Command):
await self.source_client._init_session()
await self.destination_client._init_session()
for resource in self.resources.values():
await resource.init_async()

# Validate the clients. For import we only validate the source client
# For sync/diffs we validate the destination client.
Expand Down
Loading