Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/pubsub_v1/publisher/_sequencer/base.py: 90%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

10 statements  

1# Copyright 2019, Google LLC All rights reserved. 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15from __future__ import absolute_import 

16 

17import abc 

18import typing 

19 

20from google.api_core import gapic_v1 

21from google.pubsub_v1 import types as gapic_types 

22 

23if typing.TYPE_CHECKING: # pragma: NO COVER 

24 from concurrent import futures 

25 from google.pubsub_v1.services.publisher.client import OptionalRetry 

26 

27 

28class Sequencer(metaclass=abc.ABCMeta): 

29 """The base class for sequencers for Pub/Sub publishing. A sequencer 

30 sequences messages to be published. 

31 """ 

32 

33 @abc.abstractmethod 

34 def is_finished(self) -> bool: # pragma: NO COVER 

35 """Whether the sequencer is finished and should be cleaned up. 

36 

37 Returns: 

38 bool: Whether the sequencer is finished and should be cleaned up. 

39 """ 

40 raise NotImplementedError 

41 

42 @abc.abstractmethod 

43 def unpause(self) -> None: # pragma: NO COVER 

44 """Unpauses this sequencer. 

45 

46 Raises: 

47 RuntimeError: 

48 If called when the sequencer has not been paused. 

49 """ 

50 raise NotImplementedError 

51 

52 @abc.abstractmethod 

53 def publish( 

54 self, 

55 message: gapic_types.PubsubMessage, 

56 retry: "OptionalRetry" = gapic_v1.method.DEFAULT, 

57 timeout: gapic_types.TimeoutType = gapic_v1.method.DEFAULT, 

58 ) -> "futures.Future": # pragma: NO COVER 

59 """Publish message for this ordering key. 

60 

61 Args: 

62 message: 

63 The Pub/Sub message. 

64 retry: 

65 The retry settings to apply when publishing the message. 

66 timeout: 

67 The timeout to apply when publishing the message. 

68 

69 Returns: 

70 A class instance that conforms to Python Standard library's 

71 :class:`~concurrent.futures.Future` interface. The future might return 

72 immediately with a 

73 `pubsub_v1.publisher.exceptions.PublishToPausedOrderingKeyException` 

74 if the ordering key is paused. Otherwise, the future tracks the 

75 lifetime of the message publish. 

76 

77 Raises: 

78 RuntimeError: 

79 If called after this sequencer has been stopped, either by 

80 a call to stop() or after all batches have been published. 

81 """ 

82 raise NotImplementedError