Skip to content

Commit bf93aef

Browse files
authored
fix: Feed created_at set to now (#1467)
1 parent 34ac9d3 commit bf93aef

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

functions-python/helpers/pub_sub.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def trigger_dataset_download(
8080
"""Publishes the feed to the configured Pub/Sub topic."""
8181
publisher = get_pubsub_client()
8282
topic_path = publisher.topic_path(PROJECT_ID, topic_name)
83-
logging.debug("Publishing to Pub/Sub topic: %s", topic_path)
83+
logging.info("Publishing to Pub/Sub topic: %s", topic_path)
8484

8585
message_data = {
8686
"execution_id": execution_id,
@@ -100,11 +100,15 @@ def trigger_dataset_download(
100100
future = publisher.publish(topic_path, data=json_message.encode("utf-8"))
101101
future.add_done_callback(
102102
lambda _: logging.info(
103-
"Published feed %s to dataset batch topic", feed.stable_id
103+
"Published feed %s to dataset batch topic: %s",
104+
feed.stable_id,
105+
topic_path,
104106
)
105107
)
106108
future.result()
107109
logging.info("Message published for feed %s", feed.stable_id)
108110
except Exception as e:
109-
logging.error("Error publishing to dataset batch topic: %s", str(e))
111+
logging.error(
112+
"Error publishing to dataset batch topic: %s. Error: %s", str(e), topic_path
113+
)
110114
raise

functions-python/operations_api/src/feeds_operations/impl/feeds_operations_impl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ async def create_gtfs_feed(
373373
get_execution_id(get_request_context(), "feed-created-process"),
374374
)
375375
logging.info("Created new GTFS feed with ID: %s", new_feed.stable_id)
376+
refreshed = refresh_materialized_view(db_session, t_feedsearch.name)
377+
logging.info("Materialized view %s refreshed: %s", t_feedsearch.name, refreshed)
376378
payload = OperationGtfsFeedImpl.from_orm(created_feed).model_dump()
377379
return JSONResponse(status_code=201, content=jsonable_encoder(payload))
378380

@@ -401,5 +403,7 @@ async def create_gtfs_rt_feed(
401403
db_session.commit()
402404
created_feed = db_session.get(Gtfsrealtimefeed, new_feed.id)
403405
logging.info("Created new GTFS-RT feed with ID: %s", new_feed.stable_id)
406+
refreshed = refresh_materialized_view(db_session, t_feedsearch.name)
407+
logging.info("Materialized view %s refreshed: %s", t_feedsearch.name, refreshed)
404408
payload = OperationGtfsRtFeedImpl.from_orm(created_feed).model_dump()
405409
return JSONResponse(status_code=201, content=jsonable_encoder(payload))

functions-python/operations_api/tests/feeds_operations/impl/test_create_feeds_operations_impl_gtfs.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def db_session():
6363

6464
@pytest.mark.asyncio
6565
@patch("feeds_operations.impl.feeds_operations_impl.trigger_dataset_download")
66-
async def test_create_gtfs_feed_success(mock_publish_messages, db_session):
66+
@patch("feeds_operations.impl.feeds_operations_impl.refresh_materialized_view")
67+
async def test_create_gtfs_feed_success(_, mock_publish_messages, db_session):
6768
api = OperationsApiImpl()
6869
unique_url = f"https://new-feed.example.com/{uuid.uuid4()}"
6970
request = OperationCreateRequestGtfsFeed(
@@ -140,7 +141,8 @@ async def test_create_gtfs_feed_success(mock_publish_messages, db_session):
140141

141142

142143
@pytest.mark.asyncio
143-
async def test_create_gtfs_feed_duplicate_url_rejected():
144+
@patch("feeds_operations.impl.feeds_operations_impl.refresh_materialized_view")
145+
async def test_create_gtfs_feed_duplicate_url_rejected(_):
144146
api = OperationsApiImpl()
145147
# Use a URL that normalizes to the existing feed's producer_url (from feed_mdb_40)
146148
duplicate_url = " https://PRODUCER_URL/ "
@@ -174,7 +176,8 @@ async def test_create_gtfs_feed_duplicate_url_rejected():
174176

175177

176178
@pytest.mark.asyncio
177-
async def test_create_gtfs_rt_feed_success(db_session):
179+
@patch("feeds_operations.impl.feeds_operations_impl.refresh_materialized_view")
180+
async def test_create_gtfs_rt_feed_success(_, db_session):
178181
api = OperationsApiImpl()
179182
unique_url = f"https://new-feed.example.com/{uuid.uuid4()}"
180183
request = OperationCreateRequestGtfsRtFeed(
@@ -235,7 +238,8 @@ async def test_create_gtfs_rt_feed_success(db_session):
235238

236239

237240
@pytest.mark.asyncio
238-
async def test_create_gtfs_rt_feed_duplicate_url_rejected():
241+
@patch("feeds_operations.impl.feeds_operations_impl.refresh_materialized_view")
242+
async def test_create_gtfs_rt_feed_duplicate_url_rejected(_):
239243
api = OperationsApiImpl()
240244
# Use a URL that normalizes to the existing feed's producer_url (from feed_mdb_40)
241245
duplicate_url = " https://PRODUCER_URL/ "

liquibase/changelog.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@
8282
<include file="changes/feat_1249-2.sql" relativeToChangelogFile="true"/>
8383
<!-- Materialized view recreated to return stable_ids not UIDs -->
8484
<include file="changes/feat_1396.sql" relativeToChangelogFile="true"/>
85+
<!-- Fixes feed.created_at default value -->
86+
<include file="changes/feat_1412_2.sql" relativeToChangelogFile="true"/>
8587
</databaseChangeLog>

liquibase/changes/feat_1412_2.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- This scripts fixes the default value of feed.created_at. The column created_at was defaulting to'2024-02-08 00:00:00.000000' instead of NOW.
2+
ALTER TABLE Feed ALTER COLUMN created_at SET DEFAULT NOW();

0 commit comments

Comments
 (0)