Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ src/feeds_gen/models/bounding_box.py
src/feeds_gen/models/external_id.py
src/feeds_gen/models/extra_models.py
src/feeds_gen/models/feed.py
src/feeds_gen/models/feed_related_link.py
src/feeds_gen/models/gbfs_endpoint.py
src/feeds_gen/models/gbfs_feed.py
src/feeds_gen/models/gbfs_validation_report.py
Expand Down
1 change: 1 addition & 0 deletions api/src/shared/common/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ def get_joinedload_options(include_extracted_location_entities: bool = False) ->
return joinedload_options + [
joinedload(Feed.locations),
joinedload(Feed.externalids),
joinedload(Feed.feedrelatedlinks),
joinedload(Feed.redirectingids).joinedload(Redirectingid.target),
joinedload(Feed.officialstatushistories),
]
Expand Down
2 changes: 2 additions & 0 deletions api/src/shared/db_models/feed_impl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from shared.db_models.basic_feed_impl import BaseFeedImpl
from feeds_gen.models.feed import Feed
from shared.database_gen.sqlacodegen_models import Feed as FeedOrm
from shared.db_models.feed_related_link_impl import FeedRelatedLinkImpl


class FeedImpl(BaseFeedImpl, Feed):
Expand All @@ -23,5 +24,6 @@ def from_orm(cls, feed_orm: FeedOrm | None) -> Feed | None:
feed.official = feed_orm.official
feed.official_updated_at = feed_orm.official_updated_at
feed.feed_name = feed_orm.feed_name
feed.related_links = [FeedRelatedLinkImpl.from_orm(related_link) for related_link in feed_orm.feedrelatedlinks]
feed.note = feed_orm.note
return feed
23 changes: 23 additions & 0 deletions api/src/shared/db_models/feed_related_link_impl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from feeds_gen.models.feed_related_link import FeedRelatedLink
from shared.database_gen.sqlacodegen_models import Feedrelatedlink


class FeedRelatedLinkImpl(FeedRelatedLink):
"""Implementation of the FeedRelatedLink model."""

class Config:
"""Pydantic configuration.
Enabling `from_orm` method to create a model instance from a SQLAlchemy row object."""

from_attributes = True

@classmethod
def from_orm(cls, feed_related_link_orm: Feedrelatedlink) -> FeedRelatedLink | None:
if not feed_related_link_orm:
return None
return cls(
code=feed_related_link_orm.code,
url=feed_related_link_orm.url,
description=feed_related_link_orm.description,
created_at=feed_related_link_orm.created_at,
)
2 changes: 2 additions & 0 deletions api/tests/unittest/models/test_basic_feed_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
feed_name="feed_name",
note="note",
feed_contact_email="feed_contact_email",
related_links=[],
source_info=SourceInfo(
producer_url="producer_url",
authentication_type=1,
Expand Down Expand Up @@ -149,6 +150,7 @@ def test_from_orm_empty_fields(self):
external_ids=[],
redirects=[],
source_info=SourceInfo(),
related_links=[],
)
empty_result = FeedImpl.from_orm(empty_feed_orm)
assert empty_result == expected_empty_feed
Expand Down
2 changes: 2 additions & 0 deletions api/tests/unittest/models/test_gbfs_feed_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_from_orm_all_fields(self):
expected = GbfsFeedImpl(
id="feed_stable_1",
system_id="sys1",
related_links=[],
data_type="gbfs",
created_at=datetime(2024, 1, 1, 10, 0, 0),
external_ids=[],
Expand Down Expand Up @@ -88,6 +89,7 @@ def test_from_orm_empty_fields(self):
redirects=[],
locations=[],
versions=[],
related_links=[],
bounding_box=None,
bounding_box_generated_at=None,
source_info=SourceInfo(
Expand Down
2 changes: 2 additions & 0 deletions api/tests/unittest/models/test_gtfs_feed_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def create_test_notice(notice_code: str, total_notices: int, severity: str):
feed_name="feed_name",
note="note",
feed_contact_email="feed_contact_email",
related_links=[],
source_info=SourceInfo(
producer_url="producer_url",
authentication_type=1,
Expand Down Expand Up @@ -226,6 +227,7 @@ def test_from_orm_empty_fields(self):
provider=None,
feed_name="",
note=None,
related_links=[],
feed_contact_email=None,
source_info=SourceInfo(
producer_url=None,
Expand Down
1 change: 1 addition & 0 deletions api/tests/unittest/models/test_gtfs_rt_feed_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
id="id",
data_type="gtfs_rt",
status="active",
related_links=[],
external_ids=[ExternalIdImpl(external_id="associated_id", source="source")],
provider="provider",
feed_name="feed_name",
Expand Down
1 change: 1 addition & 0 deletions api/tests/unittest/test_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"producer_url": "test_producer_url",
},
external_ids=[{"external_id": "test_associated_id", "source": "test_source"}],
related_links=[],
redirects=[{"comment": "Some comment", "target_id": "test_target_id"}],
).model_dump_json()
)
Expand Down
31 changes: 30 additions & 1 deletion docs/DatabaseCatalogAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,36 @@ components:
note:
description: A note to clarify complex use cases for consumers.
type: string

related_links:
description: >
A list of related links for the feed.
type: array
items:
$ref: '#/components/schemas/FeedRelatedLink'
FeedRelatedLink:
type: object
properties:
code:
description: >
A short code to identify the type of link.
type: string
example: next_1
description:
description: >
A description of the link.
type: string
example: The URL for a future feed version with an upcoming service period.
url:
description: >
The URL of the related link.
type: string
format: url
created_at:
description: >
The date and time the related link was created, in ISO 8601 date-time format.
type: string
example: 2023-07-10T22:06:00Z
format: date-time
GtfsFeed:
allOf:
- $ref: "#/components/schemas/Feed"
Expand Down
42 changes: 40 additions & 2 deletions docs/OperationsAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,41 @@ components:
note:
description: A note to clarify complex use cases for consumers.
type: string
related_links:
description: >
A list of related links for the feed.

type: array
items:
$ref: '#/components/schemas/FeedRelatedLink'
FeedRelatedLink:
type: object
properties:
code:
description: >
A short code to identify the type of link.

type: string
example: next_1
description:
description: >
A description of the link.

type: string
example: The URL for a future feed version with an upcoming service period.
url:
description: >
The URL of the related link.

type: string
format: url
created_at:
description: >
The date and time the related link was created, in ISO 8601 date-time format.

type: string
example: 2023-07-10T22:06:00Z
format: date-time
GtfsFeed:
allOf:
- $ref: "#/components/schemas/Feed"
Expand Down Expand Up @@ -990,7 +1025,7 @@ components:
stable_id:
description: Unique stable identifier used as a key for the feeds table.
type: string
example: mdb-1210
example: mdb-1210
operational_status:
type: string
enum: [wip, published, unpublished]
Expand All @@ -1006,7 +1041,7 @@ components:
stable_id:
description: Unique stable identifier used as a key for the feeds table.
type: string
example: mdb-1210
example: mdb-1210
operational_status:
type: string
enum: [wip, published, unpublished]
Expand Down Expand Up @@ -1058,6 +1093,7 @@ components:
description: >
The type of realtime entry:


* vp - vehicle positions
* tu - trip updates
* sa - service alerts
Expand Down Expand Up @@ -1135,6 +1171,7 @@ components:
Describes status of the Feed. Should be one of



* `active` Feed should be used in public trip planners.
* `deprecated` Feed is explicitly deprecated and should not be used in public trip planners.
* `inactive` Feed hasn't been recently updated and should be used at risk of providing outdated information.
Expand All @@ -1154,6 +1191,7 @@ components:
Describes data type of a feed. Should be one of



* `gtfs` GTFS feed.
* `gtfs_rt` GTFS-RT feed.
* `gbfs` GBFS feed.
Expand Down
1 change: 1 addition & 0 deletions functions-python/helpers/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def create_or_get_location(
municipality=city_name,
)
session.add(location)
session.flush()
logging.debug(f"Created new location: {location_id}")

return location
Expand Down
1 change: 1 addition & 0 deletions functions-python/tasks_executor/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ google-cloud-storage

# Configuration
python-dotenv==1.0.0
pycountry
5 changes: 5 additions & 0 deletions functions-python/tasks_executor/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from tasks.geojson.update_geojson_files_precision import (
update_geojson_files_precision_handler,
)
from tasks.data_import.import_jbda_feeds import import_jbda_handler

init_logger()
LIST_COMMAND: Final[str] = "list"
Expand Down Expand Up @@ -77,6 +78,10 @@
"description": "Rebuilds missing visualization files for GTFS datasets.",
"handler": rebuild_missing_visualization_files_handler,
},
"jbda_import": {
"description": "Imports JBDA data into the system.",
"handler": import_jbda_handler,
},
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
from shared.database_gen.sqlacodegen_models import Feed
import logging
import json
from google.cloud import pubsub_v1

PROJECT_ID = os.getenv("PROJECT_ID")
DATASET_BATCH_TOPIC = os.getenv("DATASET_PROCESSING_TOPIC_NAME")


def trigger_dataset_download(
feed: Feed, execution_id: str, publisher: pubsub_v1.PublisherClient
) -> None:
"""Publishes the feed to the configured Pub/Sub topic."""
topic_path = publisher.topic_path(PROJECT_ID, DATASET_BATCH_TOPIC)
logging.debug("Publishing to Pub/Sub topic: %s", topic_path)

message_data = {
"execution_id": execution_id,
"producer_url": feed.producer_url,
"feed_stable_id": feed.stable_id,
"feed_id": feed.id,
"dataset_id": None,
"dataset_hash": None,
"authentication_type": feed.authentication_type,
"authentication_info_url": feed.authentication_info_url,
"api_key_parameter_name": feed.api_key_parameter_name,
}

try:
# Convert to JSON string
json_message = json.dumps(message_data)
future = publisher.publish(topic_path, data=json_message.encode("utf-8"))
future.add_done_callback(
lambda _: logging.info(
"Published feed %s to dataset batch topic", feed.stable_id
)
)
future.result()
logging.info("Message published for feed %s", feed.stable_id)
except Exception as e:
logging.error("Error publishing to dataset batch topic: %s", str(e))
raise
Loading
Loading