Skip to content

Commit

Permalink
enhanced logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yairsimantov20 committed Jun 24, 2024
1 parent 2e2c149 commit b1548a7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
45 changes: 40 additions & 5 deletions port_ocean/core/handlers/entity_processor/jq_entity_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from dataclasses import dataclass, field
from functools import lru_cache
from typing import Any, Optional
from uuid import uuid4

import pyjq as jq # type: ignore
from loguru import logger
Expand Down Expand Up @@ -47,19 +48,53 @@ def _compile(self, pattern: str) -> Any:
return jq.compile(pattern)

async def _search(self, data: dict[str, Any], pattern: str) -> Any:
identifier = str(uuid4())
try:
loop = asyncio.get_event_loop()
logger.info(
f"__COMPILING__ jq execution with pattern: {pattern}. trace-id: {identifier}"
)
compiled_pattern = self._compile(pattern)
first_value_callable = functools.partial(compiled_pattern.first, data)
return await loop.run_in_executor(None, first_value_callable)
except Exception:
logger.info(
f"__STARTING__ jq execution with pattern: {pattern} and data: {data}. trace-id: {identifier}"
)
result = await loop.run_in_executor(None, first_value_callable)
logger.info(
f"__FINISHED__ jq execution with pattern: {pattern} and data: {data}. trace-id: {identifier} \n"
f"Result {result}"
)
return result
except Exception as e:
logger.error(
f"__FAILED__ jq execution with pattern: {pattern} and data: {data}. trace-id: {identifier} \n"
f"Error {e}"
)
return None

async def _search_as_bool(self, data: dict[str, Any], pattern: str) -> bool:
loop = asyncio.get_event_loop()
compiled_pattern = self._compile(pattern)
first_value_callable = functools.partial(compiled_pattern.first, data)
value = await loop.run_in_executor(None, first_value_callable)
identifier = str(uuid4())
try:
logger.info(
f"__COMPILING_BOOL__ jq execution with pattern: {pattern}. trace-id: {identifier}"
)
compiled_pattern = self._compile(pattern)
first_value_callable = functools.partial(compiled_pattern.first, data)
logger.info(
f"__STARTING_BOOL__ jq execution with pattern: {pattern} and data: {data}. trace-id: {identifier}"
)
value = await loop.run_in_executor(None, first_value_callable)
logger.info(
f"__FINISHED_BOOL__ jq execution with pattern: {pattern} and data: {data}. trace-id: {identifier} \n"
f"Result {value}"
)
except Exception as e:
logger.error(
f"__FAILED_BOOL__ jq execution with pattern: {pattern} and data: {data}. trace-id: {identifier} \n"
f"Error {e}"
)
raise

if isinstance(value, bool):
return value
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "port-ocean"
version = "0.9.1"
version = "0.9.2-dev01"
description = "Port Ocean is a CLI tool for managing your Port projects."
readme = "README.md"
homepage = "https://app.getport.io"
Expand Down

0 comments on commit b1548a7

Please sign in to comment.