Skip to content

Commit d67c548

Browse files
committed
Add a SyncType in type.py to avoid repeating the synctype declaration
1 parent 0b452ff commit d67c548

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

check_patroni/cli.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import re
33
from configparser import ConfigParser
4-
from typing import List, Literal
4+
from typing import List
55

66
import click
77
import nagiosplugin
@@ -34,7 +34,7 @@
3434
NodeTLHasChanged,
3535
NodeTLHasChangedSummary,
3636
)
37-
from .types import ConnectionInfo, Parameters
37+
from .types import ConnectionInfo, Parameters, SyncType
3838

3939
DEFAULT_CFG = "config.ini"
4040
handler = logging.StreamHandler()
@@ -377,7 +377,7 @@ def cluster_has_replica(
377377
critical: str,
378378
sync_warning: str,
379379
sync_critical: str,
380-
sync_type: Literal["any", "sync", "quorum"],
380+
sync_type: SyncType,
381381
max_lag: str,
382382
) -> None:
383383
"""Check if the cluster has healthy replicas and/or if some are sync or quorum standbies
@@ -647,7 +647,7 @@ def node_is_replica(
647647
max_lag: str,
648648
check_is_sync: bool,
649649
check_is_async: bool,
650-
sync_type: Literal["any", "sync", "quorum"],
650+
sync_type: SyncType,
651651
) -> None:
652652
"""Check if the node is a replica with no noloadbalance tag.
653653

check_patroni/cluster.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import hashlib
22
import json
33
from collections import Counter
4-
from typing import Any, Iterable, Literal, Union
4+
from typing import Any, Iterable, Union
55

66
import nagiosplugin
77

88
from . import _log
9-
from .types import ConnectionInfo, PatroniResource, handle_unknown
9+
from .types import ConnectionInfo, PatroniResource, SyncType, handle_unknown
1010

1111

1212
def replace_chars(text: str) -> str:
@@ -137,7 +137,7 @@ def __init__(
137137
self,
138138
connection_info: ConnectionInfo,
139139
max_lag: Union[int, None],
140-
sync_type: Literal["any", "sync", "quorum"],
140+
sync_type: SyncType,
141141
):
142142
super().__init__(connection_info)
143143
self.max_lag = max_lag

check_patroni/node.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from typing import Iterable, Literal
1+
from typing import Iterable
22

33
import nagiosplugin
44

55
from . import _log
6-
from .types import APIError, ConnectionInfo, PatroniResource, handle_unknown
6+
from .types import APIError, ConnectionInfo, PatroniResource, SyncType, handle_unknown
77

88

99
class NodeIsPrimary(PatroniResource):
@@ -65,7 +65,7 @@ def __init__(
6565
max_lag: str,
6666
check_is_sync: bool,
6767
check_is_async: bool,
68-
sync_type: Literal["any", "sync", "quorum"],
68+
sync_type: SyncType,
6969
) -> None:
7070
super().__init__(connection_info)
7171
self.max_lag = max_lag
@@ -105,7 +105,7 @@ def __init__(
105105
lag: str,
106106
check_is_sync: bool,
107107
check_is_async: bool,
108-
sync_type: Literal["any", "sync", "quorum"],
108+
sync_type: SyncType,
109109
) -> None:
110110
self.lag = lag
111111
if check_is_sync:

check_patroni/types.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
from functools import lru_cache
3-
from typing import Any, Callable, List, Optional, Tuple, Union
3+
from typing import Any, Callable, List, Literal, Optional, Tuple, Union
44
from urllib.parse import urlparse
55

66
import attr
@@ -9,6 +9,8 @@
99

1010
from . import _log
1111

12+
SyncType = Literal["any", "sync", "quorum"]
13+
1214

1315
class APIError(requests.exceptions.RequestException):
1416
"""This exception is raised when the rest api could

0 commit comments

Comments
 (0)