Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Fix linting and typing. Add requests to dependecies
Browse files Browse the repository at this point in the history
  • Loading branch information
ypkang committed Aug 20, 2024
1 parent 09c63b8 commit 9c3ea10
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
rev: v1.8.0
hooks:
- id: mypy
additional_dependencies: [types-redis, motor-types]
additional_dependencies: [types-redis, motor-types, types-requests]
exclude: 'venv|__jac_gen__|tests|setup.py'
args:
- --follow-imports=silent
Expand Down
16 changes: 10 additions & 6 deletions jaclang_jaseci/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def make_optional(cls: type) -> type:
class ElasticConnector:
"""Elastic Connector."""

url: str = ""
headers: dict = {}

@classmethod
def configure(cls, url: str) -> None:
"""Configure Elastic Connector."""
Expand All @@ -57,14 +60,14 @@ def configure(cls, url: str) -> None:
}

@classmethod
def post(cls, url_suffix: str, payload: dict = None) -> dict:
def post(cls, url_suffix: str, payload: dict) -> requests.Response:
"""Post to Elastic."""
return requests.post(
f"{cls.url}/{url_suffix}", headers=cls.headers, json=payload
)


def format_elastic_record(record: dict) -> dict:
def format_elastic_record(record: logging.LogRecord) -> dict:
# Strip out color code from message before sending to elastic
msg = record.getMessage()
msg = re.sub(r"\033\[[0-9]*m", "", msg)
Expand All @@ -85,13 +88,13 @@ def format_elastic_record(record: dict) -> dict:

def add_elastic_log_handler(
logger_instance: logging.Logger, index: str, under_test: bool = False
) -> None:
) -> Optional[multiprocessing.Queue]:
has_queue_handler = any(
isinstance(h, logging.handlers.QueueHandler) for h in logger_instance.handlers
isinstance(h, logging.handlers.QueueHandler) for h in logger_instance.handlers # type: ignore[attr-defined]
)
if not has_queue_handler:
log_queue = multiprocessing.Queue()
queue_handler = logging.handlers.QueueHandler(log_queue)
log_queue: multiprocessing.Queue = multiprocessing.Queue()
queue_handler = logging.handlers.QueueHandler(log_queue) # type: ignore[attr-defined]
logger_instance.addHandler(queue_handler)

def elastic_log_worker(elastic_index: str) -> None:
Expand Down Expand Up @@ -139,6 +142,7 @@ def elastic_log_worker(elastic_index: str) -> None:
worker_proc.start()

return log_queue
return None


def start_elastic_logger(index: str) -> None:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"nest-asyncio==1.6.0",
"fastapi-sso==0.15.0",
"google-auth==2.32.0",
"requests",
"requests>=2.32.3, <2.33.0",
"types-requests>=2.32.0, <2.33.0",
],
package_data={},
entry_points={
Expand Down

0 comments on commit 9c3ea10

Please sign in to comment.