Skip to content

Commit

Permalink
lint error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
qcdyx committed Dec 17, 2024
1 parent 996298c commit d1f7a4b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion functions-python/feed_sync_process_transitland/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from sqlalchemy.orm import Session

from helpers.database import Database, configure_polymorphic_mappers
from helpers.logger import Logger, StableIdFilter
from helpers.logger import Logger
from database_gen.sqlacodegen_models import Feed
from helpers.feed_sync.models import TransitFeedSyncPayload as FeedPayload
from .feed_processor_utils import check_url_status, create_new_feed
Expand Down
2 changes: 1 addition & 1 deletion functions-python/helpers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import logging
import os
import threading
from typing import Final, Optional
from typing import Optional

from sqlalchemy import create_engine, text, event, Engine
from sqlalchemy.orm import sessionmaker, Session, mapper, class_mapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#

import logging
import os
from typing import Annotated

from deepdiff import DeepDiff
Expand All @@ -33,7 +32,7 @@
from feeds_operations_gen.models.update_request_gtfs_rt_feed import (
UpdateRequestGtfsRtFeed,
)
from helpers.database import start_db_session, refresh_materialized_view
from helpers.database import with_db_session, refresh_materialized_view
from helpers.query_helper import query_feed_by_stable_id
from .models.update_request_gtfs_rt_feed_impl import UpdateRequestGtfsRtFeedImpl
from .request_validator import validate_request
Expand Down Expand Up @@ -107,21 +106,21 @@ async def update_gtfs_rt_feed(
- 400: Feed ID not found.
- 500: Internal server error.
"""
return await self._update_feed(update_request_gtfs_rt_feed, DataType.GTFS_RT)
return self._update_feed(update_request_gtfs_rt_feed, DataType.GTFS_RT)

@with_db_session
async def _update_feed(
self,
update_request_feed: UpdateRequestGtfsFeed | UpdateRequestGtfsRtFeed,
data_type: DataType,
db_session,
) -> Response:
"""
Update the specified feed in the Mobility Database
"""
session = None
try:
session = start_db_session(os.getenv("FEEDS_DATABASE_URL"))
feed = await OperationsApiImpl.fetch_feed(
data_type, session, update_request_feed
data_type, db_session, update_request_feed
)

logging.info(
Expand All @@ -139,14 +138,14 @@ async def _update_feed(
and update_request_feed.operational_status_action != "no_change"
):
await OperationsApiImpl._populate_feed_values(
feed, impl_class, session, update_request_feed
feed, impl_class, db_session, update_request_feed
)
session.flush()
refreshed = refresh_materialized_view(session, t_feedsearch.name)
db_session.flush()
refreshed = refresh_materialized_view(db_session, t_feedsearch.name)
logging.info(
f"Materialized view {t_feedsearch.name} refreshed: {refreshed}"
)
session.commit()
db_session.commit()
logging.info(
f"Feed ID: {update_request_feed.id} updated successfully with the following changes: "
f"{diff.values()}"
Expand All @@ -161,13 +160,9 @@ async def _update_feed(
logging.error(
f"Failed to update feed ID: {update_request_feed.id}. Error: {e}"
)
session.rollback()
if isinstance(e, HTTPException):
raise e
raise HTTPException(status_code=500, detail=f"Internal server error: {e}")
finally:
if session:
session.close()

@staticmethod
async def _populate_feed_values(feed, impl_class, session, update_request_feed):
Expand Down

0 comments on commit d1f7a4b

Please sign in to comment.