Skip to content

Commit

Permalink
expose ack id in pubsub message (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
boetro authored Dec 4, 2023
1 parent 2ed1b11 commit bd4365b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
14 changes: 6 additions & 8 deletions buildflow/io/gcp/strategies/pubsub_strategies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dataclasses
import datetime
import logging
from typing import Any, Callable, Dict, Iterable, Optional, Type, Union
from typing import Any, Callable, Iterable, Optional, Type, Union

from google.cloud.monitoring_v3 import query
from google.cloud.pubsub_v1.types import PubsubMessage as GCPPubSubMessage
Expand All @@ -21,19 +21,14 @@
from buildflow.io.strategies.source import AckInfo, PullResponse, SourceStrategy
from buildflow.io.utils.clients import gcp_clients
from buildflow.io.utils.schemas import converters
from buildflow.types.gcp import PubsubMessage


@dataclasses.dataclass(frozen=True)
class _PubsubAckInfo(AckInfo):
ack_ids: Iterable[str]


@dataclasses.dataclass
class PubsubMessage:
data: bytes
attributes: Dict[str, Any]


def _timestamp_to_datetime(timestamp: Union[datetime.datetime, Timestamp]):
if isinstance(timestamp, Timestamp):
return timestamp.ToDatetime()
Expand Down Expand Up @@ -97,7 +92,10 @@ async def pull(self) -> PullResponse:
attributes = received_message.message.attributes
for key, value in attributes.items():
att_dict[key] = value
payload = PubsubMessage(received_message.message.data, att_dict)

payload = PubsubMessage(

Check warning on line 96 in buildflow/io/gcp/strategies/pubsub_strategies.py

View check run for this annotation

Codecov / codecov/patch

buildflow/io/gcp/strategies/pubsub_strategies.py#L96

Added line #L96 was not covered by tests
received_message.message.data, att_dict, received_message.ack_id
)
elif received_message.message.data:
payload = received_message.message.data

Check warning on line 100 in buildflow/io/gcp/strategies/pubsub_strategies.py

View check run for this annotation

Codecov / codecov/patch

buildflow/io/gcp/strategies/pubsub_strategies.py#L99-L100

Added lines #L99 - L100 were not covered by tests
else:
Expand Down
8 changes: 8 additions & 0 deletions buildflow/types/gcp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dataclasses
import enum
from typing import Any, Dict

from google.cloud import storage
from pulumi_gcp.sql import ( # noqa
Expand Down Expand Up @@ -48,3 +49,10 @@ class CloudSQLDatabaseVersion:
POSTGRES_13 = "POSTGRES_13"
POSTGRES_14 = "POSTGRES_14"
POSTGRES_15 = "POSTGRES_15"


@dataclasses.dataclass
class PubsubMessage:
data: bytes
attributes: Dict[str, Any]
ack_id: str

0 comments on commit bd4365b

Please sign in to comment.