-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ignore the implementation details of message acknowledgements fr…
…om the cloud Pub/Sub Message (#312) * fix: ignore the implementation details of message acknowledgements from the cloud Pub/Sub Message fixes: #311 * fix: ignore the implementation details of message acknowledgements from the cloud Pub/Sub Message fixes: #311 * fix: ignore the implementation details of message acknowledgements from the cloud Pub/Sub Message fixes: #311 * fix: ignore the implementation details of message acknowledgements from the cloud Pub/Sub Message fixes: #311 * fix: ignore the implementation details of message acknowledgements from the cloud Pub/Sub Message fixes: #311
- Loading branch information
1 parent
1d223f4
commit 19da693
Showing
3 changed files
with
100 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
google/cloud/pubsublite/cloudpubsub/internal/wrapped_message.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from concurrent import futures | ||
import logging | ||
from typing import NamedTuple, Callable | ||
|
||
from google.cloud.pubsub_v1.subscriber.message import Message | ||
from google.pubsub_v1 import PubsubMessage | ||
from google.cloud.pubsub_v1.subscriber.exceptions import AcknowledgeStatus | ||
|
||
|
||
class AckId(NamedTuple): | ||
generation: int | ||
offset: int | ||
|
||
def encode(self) -> str: | ||
return str(self.generation) + "," + str(self.offset) | ||
|
||
|
||
_SUCCESS_FUTURE = futures.Future() | ||
_SUCCESS_FUTURE.set_result(AcknowledgeStatus.SUCCESS) | ||
|
||
|
||
class WrappedMessage(Message): | ||
_id: AckId | ||
_ack_handler: Callable[[AckId, bool], None] | ||
|
||
def __init__( | ||
self, | ||
pb: PubsubMessage.meta.pb, | ||
ack_id: AckId, | ||
ack_handler: Callable[[AckId, bool], None], | ||
): | ||
super().__init__(pb, ack_id.encode(), 1, None) | ||
self._id = ack_id | ||
self._ack_handler = ack_handler | ||
|
||
def ack(self): | ||
self._ack_handler(self._id, True) | ||
|
||
def ack_with_response(self) -> "futures.Future": | ||
self._ack_handler(self._id, True) | ||
return _SUCCESS_FUTURE | ||
|
||
def nack(self): | ||
self._ack_handler(self._id, False) | ||
|
||
def nack_with_response(self) -> "futures.Future": | ||
self._ack_handler(self._id, False) | ||
return _SUCCESS_FUTURE | ||
|
||
def drop(self): | ||
logging.warning( | ||
"Likely incorrect call to drop() on Pub/Sub Lite message. Pub/Sub Lite does not support redelivery in this way." | ||
) | ||
|
||
def modify_ack_deadline(self, seconds: int): | ||
logging.warning( | ||
"Likely incorrect call to modify_ack_deadline() on Pub/Sub Lite message. Pub/Sub Lite does not support redelivery in this way." | ||
) | ||
|
||
def modify_ack_deadline_with_response(self, seconds: int) -> "futures.Future": | ||
logging.warning( | ||
"Likely incorrect call to modify_ack_deadline_with_response() on Pub/Sub Lite message. Pub/Sub Lite does not support redelivery in this way." | ||
) | ||
return _SUCCESS_FUTURE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters