Skip to content

Commit

Permalink
Fix pagerduty loader
Browse files Browse the repository at this point in the history
  • Loading branch information
david1542 committed Aug 15, 2024
1 parent 3b8d916 commit 3bc248b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
12 changes: 8 additions & 4 deletions services/data-processor/src/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ async def get_documents(
continue

# Loader might be an async code, so we need to await it
if asyncio.iscoroutinefunction(loader):
docs = await loader(integration)
else:
docs = loader(integration)
try:
if asyncio.iscoroutinefunction(loader):
docs = await loader(integration)
else:
docs = loader(integration)
except Exception as e:
print(f"Could not load {vendor_name}. Error: {e}")
continue

progress_bar.set_description(f"Transforming {vendor_name}")
pipeline = IngestionPipeline(
Expand Down
16 changes: 12 additions & 4 deletions services/data-processor/src/loaders/pagerduty.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@
"""


async def get_incidents(access_token: str):
headers = {"Authorization": f"Bearer {access_token}"}
async def get_incidents(integration: Integration):
access_token = integration.access_token
integration_type = integration.type
headers = {}
if integration_type == "basic":
headers["Authorization"] = f"Token token={access_token}"
elif integration_type == "oauth":
headers["Authorization"] = f"Bearer {access_token}"
else:
raise ValueError(f"Invalid integration type: {integration_type}")

limit = 100
offset = 0
resolved_incidents = []
Expand All @@ -39,8 +48,7 @@ async def get_incidents(access_token: str):


async def fetch_pagerduty_documents(integration: Integration):
access_token = integration.credentials["access_token"]
incidents = await get_incidents(access_token)
incidents = await get_incidents(integration)

documents = []
for incident in incidents:
Expand Down

0 comments on commit 3bc248b

Please sign in to comment.