1# Copyright 2017, 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
15import typing
16from typing import NamedTuple, Optional
17
18from google.cloud.pubsub_v1.open_telemetry.subscribe_opentelemetry import (
19 SubscribeOpenTelemetry,
20)
21
22if typing.TYPE_CHECKING: # pragma: NO COVER
23 from google.cloud.pubsub_v1.subscriber import futures
24
25
26# Namedtuples for management requests. Used by the Message class to communicate
27# items of work back to the policy.
28class AckRequest(NamedTuple):
29 ack_id: str
30 byte_size: int
31 time_to_ack: float
32 ordering_key: Optional[str]
33 future: Optional["futures.Future"]
34 opentelemetry_data: Optional[SubscribeOpenTelemetry] = None
35 message_id: Optional[str] = None
36
37
38class DropRequest(NamedTuple):
39 ack_id: str
40 byte_size: int
41 ordering_key: Optional[str]
42
43
44class LeaseRequest(NamedTuple):
45 ack_id: str
46 byte_size: int
47 ordering_key: Optional[str]
48 opentelemetry_data: Optional[SubscribeOpenTelemetry] = None
49
50
51class ModAckRequest(NamedTuple):
52 ack_id: str
53 seconds: float
54 future: Optional["futures.Future"]
55 opentelemetry_data: Optional[SubscribeOpenTelemetry] = None
56 message_id: Optional[str] = None
57
58
59class NackRequest(NamedTuple):
60 ack_id: str
61 byte_size: int
62 ordering_key: Optional[str]
63 future: Optional["futures.Future"]
64 opentelemetry_data: Optional[SubscribeOpenTelemetry] = None