Skip to content

Commit

Permalink
Increment version of ltd_url_ingest schema to v2
Browse files Browse the repository at this point in the history
Since the DocumentSourceType enum changed, we need new schemas.
  • Loading branch information
jonathansick committed Sep 26, 2023
1 parent 5aab88c commit 7a2334f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/ook/domain/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"UrlIngestKeyV1",
"LtdEditionV1",
"LtdProjectV1",
"LtdUrlIngestV1",
"LtdUrlIngestV2",
]


Expand Down Expand Up @@ -61,7 +61,7 @@ class LtdProjectV1(AvroBaseModel):
slug: str = Field(..., description="The slug of the project.")


class LtdUrlIngestV1(AvroBaseModel):
class LtdUrlIngestV2(AvroBaseModel):
"""Kafka message value model for a request to ingest a URL hosted on
LSST the Docs.
Expand Down Expand Up @@ -91,4 +91,4 @@ class Meta:
"""Metadata for the model."""

namespace = "lsst.square-events.ook"
schema_name = "ltd_url_ingest_v1"
schema_name = "ltd_url_ingest_v2"
4 changes: 2 additions & 2 deletions src/ook/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from .config import config
from .dependencies.algoliasearch import algolia_client_dependency
from .domain.kafka import LtdUrlIngestV1, UrlIngestKeyV1
from .domain.kafka import LtdUrlIngestV2, UrlIngestKeyV1
from .services.algoliaaudit import AlgoliaAuditService
from .services.algoliadocindex import AlgoliaDocIndexService
from .services.classification import ClassificationService
Expand Down Expand Up @@ -67,7 +67,7 @@ async def create(cls) -> ProcessContext:
registry_url=config.registry_url,
models=[
UrlIngestKeyV1,
LtdUrlIngestV1,
LtdUrlIngestV2,
],
suffix=config.subject_suffix,
compatibility=config.subject_compatibility,
Expand Down
4 changes: 2 additions & 2 deletions src/ook/handlers/kafka/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from structlog.stdlib import BoundLogger

from ook.domain.algoliarecord import DocumentSourceType
from ook.domain.kafka import LtdUrlIngestV1, UrlIngestKeyV1
from ook.domain.kafka import LtdUrlIngestV2, UrlIngestKeyV1
from ook.factory import Factory

if TYPE_CHECKING:
Expand Down Expand Up @@ -46,7 +46,7 @@ async def handle_ltd_document_ingest(
*,
message_metadata: MessageMetadata,
key: UrlIngestKeyV1,
value: LtdUrlIngestV1,
value: LtdUrlIngestV2,
**kwargs: Any,
) -> None:
"""Handle a message requesting an ingest for an LTD document."""
Expand Down
4 changes: 2 additions & 2 deletions src/ook/handlers/kafka/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from ook.config import config
from ook.dependencies.context import context_dependency
from ook.domain.kafka import LtdUrlIngestV1, UrlIngestKeyV1
from ook.domain.kafka import LtdUrlIngestV2, UrlIngestKeyV1
from ook.handlers.kafka.handlers import handle_ltd_document_ingest


Expand Down Expand Up @@ -261,6 +261,6 @@ async def consume_kafka_messages() -> None:
cast(HandlerProtocol, handle_ltd_document_ingest),
[config.ingest_kafka_topic],
[UrlIngestKeyV1],
[LtdUrlIngestV1],
[LtdUrlIngestV2],
)
await consumer.start()
4 changes: 2 additions & 2 deletions src/ook/services/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from ook.domain.kafka import (
LtdEditionV1,
LtdProjectV1,
LtdUrlIngestV1,
LtdUrlIngestV2,
UrlIngestKeyV1,
)
from ook.services.kafkaproducer import PydanticKafkaProducer
Expand Down Expand Up @@ -116,7 +116,7 @@ async def queue_ingest_for_ltd_product_slug(

try:
kafka_key = UrlIngestKeyV1(url=published_url)
kafka_value = LtdUrlIngestV1(
kafka_value = LtdUrlIngestV2(
url=published_url,
content_type=content_type,
request_timestamp=datetime.now(tz=UTC),
Expand Down
10 changes: 5 additions & 5 deletions tests/domain/test_kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import json

from ook.domain.kafka import LtdUrlIngestV1, UrlIngestKeyV1
from ook.domain.kafka import LtdUrlIngestV2, UrlIngestKeyV1


def test_url_ingest_key_v1() -> None:
Expand All @@ -14,8 +14,8 @@ def test_url_ingest_key_v1() -> None:
assert schema["namespace"] == "lsst.square-events.ook"


def test_ltd_url_ingest_v1() -> None:
"""Test the ``LtdUrlIngestV1`` model."""
schema = json.loads(LtdUrlIngestV1.avro_schema())
assert schema["name"] == "ltd_url_ingest_v1"
def test_ltd_url_ingest_v2() -> None:
"""Test the ``LtdUrlIngestV2`` model."""
schema = json.loads(LtdUrlIngestV2.avro_schema())
assert schema["name"] == "ltd_url_ingest_v2"
assert schema["namespace"] == "lsst.square-events.ook"

0 comments on commit 7a2334f

Please sign in to comment.