SIENTIAPDE-1163
refactor: update MongoDB notification IDs for error handling in activities; add tests for error scenarios in MongoDB and TemporalManager activities to ensure proper notification sending on failures
This commit is contained in:
@@ -220,7 +220,7 @@ class MongoDB(BaseActivity):
|
||||
trace = traceback.format_exc()
|
||||
self.send_notification(
|
||||
metadata=metadata,
|
||||
notification_id="MONGODB_UPDATE_ERROR",
|
||||
notification_id="MONGODB_UPDATE_PIPELINES_ERROR",
|
||||
message=f"Failed to update pipelines timestamps: {e}",
|
||||
block="update_pipelines_timestamps",
|
||||
level=NotificationLevel.ERROR,
|
||||
@@ -256,7 +256,7 @@ class MongoDB(BaseActivity):
|
||||
trace = traceback.format_exc()
|
||||
self.send_notification(
|
||||
metadata=metadata,
|
||||
notification_id="MONGODB_INSERT_ERROR",
|
||||
notification_id="MONGODB_CREATE_PIPELINES_ERROR",
|
||||
message=f"Failed to create pipelines timestamps: {e}",
|
||||
block="create_pipelines_timestamps",
|
||||
level=NotificationLevel.ERROR,
|
||||
@@ -289,7 +289,7 @@ class MongoDB(BaseActivity):
|
||||
trace = traceback.format_exc()
|
||||
self.send_notification(
|
||||
metadata=metadata,
|
||||
notification_id="MONGODB_DELETE_ERROR",
|
||||
notification_id="MONGODB_DELETE_PIPELINES_ERROR",
|
||||
message=f"Failed to delete pipelines timestamps: {e}",
|
||||
block="delete_pipelines_timestamps",
|
||||
level=NotificationLevel.ERROR,
|
||||
|
||||
@@ -63,90 +63,6 @@ class TemporalManager(BaseActivity):
|
||||
self.laborious_namespace: laborious_client
|
||||
}
|
||||
|
||||
@activity.defn(name="load_schedule")
|
||||
async def load_schedule(self, input_data: dict[str, Any]) -> dict[str, Any]:
|
||||
"""
|
||||
Load all orchestrated schedules from Temporal. Filters by search attribute
|
||||
"Orchestrated" set to "true" and returns a dictionary of schedule_id:
|
||||
{frequency, data, handle}
|
||||
|
||||
Returns:
|
||||
dict[str, Any]: A dictionary of orchestrated schedules
|
||||
"""
|
||||
|
||||
metadata = input_data.get("metadata", {})
|
||||
|
||||
self.logger.info("Getting orchestrated schedules...")
|
||||
|
||||
orchestrated_schedules = {}
|
||||
|
||||
try:
|
||||
|
||||
for namespace, client in self.temporal_clients.items():
|
||||
orchestrated_schedules[namespace] = {}
|
||||
|
||||
self.logger.info(
|
||||
f"Getting orchestrated schedules for {namespace}")
|
||||
|
||||
async for schedule in await client.list_schedules():
|
||||
search_attrs = getattr(schedule, "search_attributes", {})
|
||||
if search_attrs.get("orchestrated", ["false"]) == ["true"]:
|
||||
schedule_id = schedule.id
|
||||
|
||||
self.logger.debug(f"Schedule id: {schedule_id}")
|
||||
|
||||
handle = client.get_schedule_handle(
|
||||
schedule_id)
|
||||
|
||||
self.logger.debug("Handle acquired")
|
||||
|
||||
self.schedule_handles[namespace][schedule_id] = handle
|
||||
|
||||
self.logger.debug("Describing schedule...")
|
||||
|
||||
desc = await handle.describe(
|
||||
rpc_timeout=timedelta(seconds=60)
|
||||
)
|
||||
|
||||
self.logger.debug("Parsing args...")
|
||||
|
||||
for arg in desc.schedule.action.args:
|
||||
data = MessageToDict(arg)['data']
|
||||
data = base64.b64decode(data).decode('utf-8')
|
||||
|
||||
frequency = desc.schedule.spec.intervals[0].every.seconds
|
||||
|
||||
orchestrated_schedules[namespace][schedule_id] = {
|
||||
'frequency': frequency,
|
||||
'data': json.loads(data),
|
||||
}
|
||||
|
||||
await sleep(0.1)
|
||||
|
||||
except Exception as e:
|
||||
trace = traceback.format_exc()
|
||||
self.send_notification(
|
||||
metadata=metadata,
|
||||
notification_id="TEMPORAL_LOAD_SCHEDULE_ERROR",
|
||||
message=f"Failed to load orchestrated schedules: {e}",
|
||||
block="load_schedule",
|
||||
level=NotificationLevel.ERROR,
|
||||
attachment_content=trace
|
||||
)
|
||||
self.logger.error(trace)
|
||||
raise e
|
||||
|
||||
self.logger.info(
|
||||
f"Found {len(orchestrated_schedules[self.scouter_namespace]) + len(orchestrated_schedules[self.laborious_namespace])} orchestrated schedules")
|
||||
|
||||
self.logger.debug(
|
||||
f"Orchestrated schedules: {orchestrated_schedules}")
|
||||
|
||||
self.logger.debug(
|
||||
f"Schedule handles: {self.schedule_handles}")
|
||||
|
||||
return orchestrated_schedules
|
||||
|
||||
@activity.defn(name="normalize_schedules")
|
||||
async def normalize_schedules(self, input_data: dict[str, Any]) -> dict[str, Any]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user