Skip to content

Commit

Permalink
Add a SyncType in type.py to avoid repeating the synctype declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
blogh committed Jan 20, 2025
1 parent 0b452ff commit d67c548
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
8 changes: 4 additions & 4 deletions check_patroni/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import re
from configparser import ConfigParser
from typing import List, Literal
from typing import List

import click
import nagiosplugin
Expand Down Expand Up @@ -34,7 +34,7 @@
NodeTLHasChanged,
NodeTLHasChangedSummary,
)
from .types import ConnectionInfo, Parameters
from .types import ConnectionInfo, Parameters, SyncType

DEFAULT_CFG = "config.ini"
handler = logging.StreamHandler()
Expand Down Expand Up @@ -377,7 +377,7 @@ def cluster_has_replica(
critical: str,
sync_warning: str,
sync_critical: str,
sync_type: Literal["any", "sync", "quorum"],
sync_type: SyncType,
max_lag: str,
) -> None:
"""Check if the cluster has healthy replicas and/or if some are sync or quorum standbies
Expand Down Expand Up @@ -647,7 +647,7 @@ def node_is_replica(
max_lag: str,
check_is_sync: bool,
check_is_async: bool,
sync_type: Literal["any", "sync", "quorum"],
sync_type: SyncType,
) -> None:
"""Check if the node is a replica with no noloadbalance tag.
Expand Down
6 changes: 3 additions & 3 deletions check_patroni/cluster.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import hashlib
import json
from collections import Counter
from typing import Any, Iterable, Literal, Union
from typing import Any, Iterable, Union

import nagiosplugin

from . import _log
from .types import ConnectionInfo, PatroniResource, handle_unknown
from .types import ConnectionInfo, PatroniResource, SyncType, handle_unknown


def replace_chars(text: str) -> str:
Expand Down Expand Up @@ -137,7 +137,7 @@ def __init__(
self,
connection_info: ConnectionInfo,
max_lag: Union[int, None],
sync_type: Literal["any", "sync", "quorum"],
sync_type: SyncType,
):
super().__init__(connection_info)
self.max_lag = max_lag
Expand Down
8 changes: 4 additions & 4 deletions check_patroni/node.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Iterable, Literal
from typing import Iterable

import nagiosplugin

from . import _log
from .types import APIError, ConnectionInfo, PatroniResource, handle_unknown
from .types import APIError, ConnectionInfo, PatroniResource, SyncType, handle_unknown


class NodeIsPrimary(PatroniResource):
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(
max_lag: str,
check_is_sync: bool,
check_is_async: bool,
sync_type: Literal["any", "sync", "quorum"],
sync_type: SyncType,
) -> None:
super().__init__(connection_info)
self.max_lag = max_lag
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(
lag: str,
check_is_sync: bool,
check_is_async: bool,
sync_type: Literal["any", "sync", "quorum"],
sync_type: SyncType,
) -> None:
self.lag = lag
if check_is_sync:
Expand Down
4 changes: 3 additions & 1 deletion check_patroni/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from functools import lru_cache
from typing import Any, Callable, List, Optional, Tuple, Union
from typing import Any, Callable, List, Literal, Optional, Tuple, Union
from urllib.parse import urlparse

import attr
Expand All @@ -9,6 +9,8 @@

from . import _log

SyncType = Literal["any", "sync", "quorum"]


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

0 comments on commit d67c548

Please sign in to comment.