@@ -106,56 +106,55 @@ async def update_gtfs_rt_feed(
106106 - 400: Feed ID not found.
107107 - 500: Internal server error.
108108 """
109- return self ._update_feed (update_request_gtfs_rt_feed , DataType .GTFS_RT )
109+ return await self ._update_feed (update_request_gtfs_rt_feed , DataType .GTFS_RT )
110110
111- @with_db_session
112111 async def _update_feed (
113112 self ,
114113 update_request_feed : UpdateRequestGtfsFeed | UpdateRequestGtfsRtFeed ,
115114 data_type : DataType ,
116- db_session ,
117115 ) -> Response :
118116 """
119117 Update the specified feed in the Mobility Database
120118 """
121119 try :
122- feed = await OperationsApiImpl .fetch_feed (
123- data_type , db_session , update_request_feed
124- )
125-
126- logging .info (
127- f"Feed ID: { update_request_feed .id } attempting to update with the following request: "
128- f"{ update_request_feed } "
129- )
130- impl_class = (
131- UpdateRequestGtfsFeedImpl
132- if data_type == DataType .GTFS
133- else UpdateRequestGtfsRtFeedImpl
134- )
135- diff = self .detect_changes (feed , update_request_feed , impl_class )
136- if len (diff .affected_paths ) > 0 or (
137- update_request_feed .operational_status_action is not None
138- and update_request_feed .operational_status_action != "no_change"
139- ):
140- await OperationsApiImpl ._populate_feed_values (
141- feed , impl_class , db_session , update_request_feed
120+ with with_db_session () as db_session :
121+ feed = await OperationsApiImpl .fetch_feed (
122+ data_type , db_session , update_request_feed
142123 )
143- db_session .flush ()
144- refreshed = refresh_materialized_view (db_session , t_feedsearch .name )
145- logging .info (
146- f"Materialized view { t_feedsearch .name } refreshed: { refreshed } "
147- )
148- db_session .commit ()
124+
149125 logging .info (
150- f"Feed ID: { update_request_feed .id } updated successfully with the following changes : "
151- f"{ diff . values () } "
126+ f"Feed ID: { update_request_feed .id } attempting to update with the following request : "
127+ f"{ update_request_feed } "
152128 )
153- return Response ( status_code = 200 )
154- else :
155- logging . info (
156- f"No changes detected for feed ID: { update_request_feed . id } "
129+ impl_class = (
130+ UpdateRequestGtfsFeedImpl
131+ if data_type == DataType . GTFS
132+ else UpdateRequestGtfsRtFeedImpl
157133 )
158- return Response (status_code = 204 )
134+ diff = self .detect_changes (feed , update_request_feed , impl_class )
135+ if len (diff .affected_paths ) > 0 or (
136+ update_request_feed .operational_status_action is not None
137+ and update_request_feed .operational_status_action != "no_change"
138+ ):
139+ await OperationsApiImpl ._populate_feed_values (
140+ feed , impl_class , db_session , update_request_feed
141+ )
142+ db_session .flush ()
143+ refreshed = refresh_materialized_view (db_session , t_feedsearch .name )
144+ logging .info (
145+ f"Materialized view { t_feedsearch .name } refreshed: { refreshed } "
146+ )
147+ db_session .commit ()
148+ logging .info (
149+ f"Feed ID: { update_request_feed .id } updated successfully with the following changes: "
150+ f"{ diff .values ()} "
151+ )
152+ return Response (status_code = 200 )
153+ else :
154+ logging .info (
155+ f"No changes detected for feed ID: { update_request_feed .id } "
156+ )
157+ return Response (status_code = 204 )
159158 except Exception as e :
160159 logging .error (
161160 f"Failed to update feed ID: { update_request_feed .id } . Error: { e } "
0 commit comments