-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/add-logging-to-reports
- Loading branch information
Showing
117 changed files
with
2,852 additions
and
1,211 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
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
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
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
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
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
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
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
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
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,6 @@ | ||
from .amqp.raw_data import RawData | ||
from .amqp.scan_profile import ScanProfileMutation | ||
from .http.external.bytes import Bytes | ||
from .http.external.katalogus import Katalogus | ||
from .http.external.octopoes import Octopoes | ||
from .http.external.rocky import Rocky |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,2 @@ | ||
from .client import HTTPClient | ||
from .service import HTTPService |
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,77 @@ | ||
import socket | ||
import time | ||
from collections.abc import Callable | ||
|
||
import httpx | ||
import structlog | ||
|
||
|
||
class HTTPClient: | ||
"""A class that provides methods to check if a host is available and healthy.""" | ||
|
||
def __init__(self): | ||
self.logger = structlog.get_logger(self.__class__.__name__) | ||
|
||
def is_host_available(self, hostname: str, port: int) -> bool: | ||
"""Check if the host is available. | ||
Args: | ||
hostname: A string representing the hostname. | ||
port: An integer representing the port number. | ||
Returns: | ||
A boolean | ||
""" | ||
try: | ||
socket.create_connection((hostname, port)) | ||
return True | ||
except OSError: | ||
return False | ||
|
||
def is_host_healthy(self, host: str, health_endpoint: str) -> bool: | ||
"""Check if host is healthy by inspecting the host's health endpoint. | ||
Args: | ||
host: A string representing the hostname. | ||
health_endpoint: A string representing the health endpoint. | ||
Returns: | ||
A boolean | ||
""" | ||
try: | ||
url = f"{host}/{health_endpoint}" | ||
response = httpx.get(url, timeout=5) | ||
healthy = response.json().get("healthy") | ||
return healthy | ||
except httpx.HTTPError as exc: | ||
self.logger.warning("Exception: %s", exc) | ||
return False | ||
|
||
def retry(self, func: Callable, *args, **kwargs) -> bool: | ||
"""Retry a function until it returns True. | ||
Args: | ||
func: A python callable that needs to be retried. | ||
Returns: | ||
A boolean signifying whether or not the func was executed successfully. | ||
""" | ||
for i in range(10): | ||
if func(*args, **kwargs): | ||
self.logger.info( | ||
"Function %s, executed successfully. Retry count: %d", | ||
func.__name__, | ||
i, | ||
name=func.__name__, | ||
args=args, | ||
kwargs=kwargs, | ||
) | ||
return True | ||
|
||
self.logger.warning( | ||
"Function %s, failed. Retry count: %d", func.__name__, i, name=func.__name__, args=args, kwargs=kwargs | ||
) | ||
|
||
time.sleep(10) | ||
|
||
return False |
File renamed without changes.
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
Oops, something went wrong.