SIENTIAPDE-1150
refactor: streamline MongoDB activity methods to improve readability and maintainability; replace inline query construction with variable assignments for updated, created, and deleted pipelines
This commit is contained in:
@@ -198,12 +198,14 @@ class MongoDB(BaseActivity):
|
|||||||
updated_pipelines = input_data.get("updated_pipelines", [])
|
updated_pipelines = input_data.get("updated_pipelines", [])
|
||||||
now = datetime.now().strftime(DEFAULT_DATE_FORMAT)
|
now = datetime.now().strftime(DEFAULT_DATE_FORMAT)
|
||||||
|
|
||||||
|
argument = [
|
||||||
|
{"schedule_name": pipeline["schedule_name"],
|
||||||
|
"namespace": pipeline["namespace"]}
|
||||||
|
for pipeline in updated_pipelines if pipeline["success"]
|
||||||
|
]
|
||||||
|
data_filter = {"$or": argument} if argument else {}
|
||||||
self.database["pipelines"].update_many(
|
self.database["pipelines"].update_many(
|
||||||
{"$or": [
|
data_filter,
|
||||||
{"schedule_name": pipeline["schedule_name"],
|
|
||||||
"namespace": pipeline["namespace"]}
|
|
||||||
for pipeline in updated_pipelines if pipeline["success"]
|
|
||||||
]},
|
|
||||||
{"$set": {"updated_at": now}}
|
{"$set": {"updated_at": now}}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -218,11 +220,14 @@ class MongoDB(BaseActivity):
|
|||||||
|
|
||||||
now = datetime.now().strftime(DEFAULT_DATE_FORMAT)
|
now = datetime.now().strftime(DEFAULT_DATE_FORMAT)
|
||||||
|
|
||||||
self.database["pipelines"].insert_many([{
|
argument = [
|
||||||
"schedule_name": pipeline["schedule_name"],
|
{"schedule_name": pipeline["schedule_name"],
|
||||||
"namespace": pipeline["namespace"],
|
"namespace": pipeline["namespace"],
|
||||||
"updated_at": now
|
"updated_at": now}
|
||||||
} for pipeline in created_pipelines if pipeline["success"]])
|
for pipeline in created_pipelines if pipeline["success"]
|
||||||
|
]
|
||||||
|
data_filter = argument if argument else {}
|
||||||
|
self.database["pipelines"].insert_many(data_filter)
|
||||||
|
|
||||||
@activity.defn(name="delete_pipelines_timestamps")
|
@activity.defn(name="delete_pipelines_timestamps")
|
||||||
async def delete_pipelines_timestamps(self, input_data: dict[str, Any]) -> None:
|
async def delete_pipelines_timestamps(self, input_data: dict[str, Any]) -> None:
|
||||||
@@ -233,10 +238,11 @@ class MongoDB(BaseActivity):
|
|||||||
"""
|
"""
|
||||||
deleted_pipelines = input_data.get("deleted_pipelines", [])
|
deleted_pipelines = input_data.get("deleted_pipelines", [])
|
||||||
|
|
||||||
self.database["pipelines"].delete_many({
|
argument = [
|
||||||
"$or": [
|
{"schedule_name": pipeline["schedule_name"],
|
||||||
{"schedule_name": pipeline["schedule_name"],
|
"namespace": pipeline["namespace"]}
|
||||||
"namespace": pipeline["namespace"]}
|
for pipeline in deleted_pipelines if pipeline["success"]
|
||||||
for pipeline in deleted_pipelines if pipeline["success"]
|
]
|
||||||
]
|
data_filter = {"$or": argument} if argument else {}
|
||||||
})
|
|
||||||
|
self.database["pipelines"].delete_many(data_filter)
|
||||||
|
|||||||
Reference in New Issue
Block a user