diff --git a/api/helpers/common_helper.py b/api/helpers/common_helper.py index cecf62b..6efb656 100644 --- a/api/helpers/common_helper.py +++ b/api/helpers/common_helper.py @@ -5,13 +5,9 @@ def get_current_utc_timestamp() -> datetime: return datetime.now(timezone.utc) -def check_activity_key( - activity_key: str, activity_value: str, keyword: str, status: str -): +def validate_activity_status(activity_key: str, keyword: str, status: str): return ( True - if activity_key.startswith(keyword) - and activity_key.endswith(status) - and activity_value == "yes" + if activity_key.startswith(keyword) and activity_key.endswith(status) else False ) diff --git a/api/services/flow_run_log_service.py b/api/services/flow_run_log_service.py index d02bab5..561efdf 100644 --- a/api/services/flow_run_log_service.py +++ b/api/services/flow_run_log_service.py @@ -26,10 +26,15 @@ def create_user_flow_log(self, json_data: dict[str, Any]) -> models.UserFlows: ) ) - if flow_status == self.class_model.FlowRunStatus.SENT: + if flow_status == self.class_model.FlowRunStatus.SENT or ( + flow_status == self.class_model.FlowRunStatus.COMPLETED + and latest_flow_log is None + ): user_flow_log = self.create_log(flow_uuid, flow_name, flow_type) elif flow_status == self.class_model.FlowRunStatus.COMPLETED: user_flow_log = self.update_log(latest_flow_log) + else: + user_flow_log = latest_flow_log except Exception as e: logger.error( diff --git a/api/services/user_activities_service.py b/api/services/user_activities_service.py index 0754341..5982f54 100644 --- a/api/services/user_activities_service.py +++ b/api/services/user_activities_service.py @@ -17,9 +17,9 @@ def handle_user_activities(self, json_data: dict[str, Any]): try: current_time = common_helper.get_current_utc_timestamp() - for activity_key, activity_value in json_data.items(): + for activity_key, _ in json_data.items(): user_activity = self.create_or_update_user_activity( - activity_key, activity_value, current_time + activity_key, current_time ) if user_activity: db.session.add(user_activity) @@ -33,16 +33,16 @@ def handle_user_activities(self, json_data: dict[str, Any]): ) def create_or_update_user_activity( - self, activity_key: str, activity_value: str, current_time: datetime + self, activity_key: str, current_time: datetime ) -> Optional[models.UserActivities]: - is_started = common_helper.check_activity_key( - activity_key, activity_value, "activity_", "_started" + is_started = common_helper.validate_activity_status( + activity_key, "activity_", "_started" ) - is_succeeded = common_helper.check_activity_key( - activity_key, activity_value, "activity_", "_success" + is_succeeded = common_helper.validate_activity_status( + activity_key, "activity_", "_success" ) - is_completed = common_helper.check_activity_key( - activity_key, activity_value, "activity_", "_completed" + is_completed = common_helper.validate_activity_status( + activity_key, "activity_", "_completed" ) if is_started: