fix(sentry): only import/run Sentry if enabled
This commit is contained in:
@ -1,10 +1,12 @@
|
||||
"""N8N utils module."""
|
||||
|
||||
import requests
|
||||
import sentry_sdk
|
||||
|
||||
from app.utils.config import config
|
||||
|
||||
if config.sentry_enabled:
|
||||
import sentry_sdk
|
||||
|
||||
|
||||
def __n8n_post(data: dict) -> bool:
|
||||
"""Post data to N8N webhook URL.
|
||||
@ -38,15 +40,18 @@ def submit_task(summary, description, completion_date, requestor) -> bool:
|
||||
Returns:
|
||||
bool: True if successful, else False.
|
||||
"""
|
||||
with sentry_sdk.start_transaction(name="submit_task"):
|
||||
data: dict = {
|
||||
"requestor": requestor,
|
||||
"title": summary,
|
||||
"description": description,
|
||||
"completiondate": completion_date,
|
||||
}
|
||||
data: dict = {
|
||||
"requestor": requestor,
|
||||
"title": summary,
|
||||
"description": description,
|
||||
"completiondate": completion_date,
|
||||
}
|
||||
if not config.sentry_enabled:
|
||||
_data = __n8n_post(data=data)
|
||||
return _data
|
||||
return _data
|
||||
with sentry_sdk.start_transaction(name="submit_task"):
|
||||
_data = __n8n_post(data=data)
|
||||
return _data
|
||||
|
||||
|
||||
def get_tasks(requestor) -> bool:
|
||||
@ -58,8 +63,8 @@ def get_tasks(requestor) -> bool:
|
||||
Returns:
|
||||
bool: True if successful, else False.
|
||||
"""
|
||||
with sentry_sdk.start_transaction(name="get_tasks"):
|
||||
headers: dict = {"Content-Type": "application/json"}
|
||||
headers: dict = {"Content-Type": "application/json"}
|
||||
if not config.sentry_enabled:
|
||||
resp: requests.Response = requests.get(
|
||||
url=config.n8n_webhook_url,
|
||||
headers=headers,
|
||||
@ -68,4 +73,14 @@ def get_tasks(requestor) -> bool:
|
||||
params={"requestor": requestor},
|
||||
)
|
||||
_data = bool(resp.status_code == 200)
|
||||
return _data
|
||||
return _data
|
||||
with sentry_sdk.start_transaction(name="get_tasks"):
|
||||
resp: requests.Response = requests.get(
|
||||
url=config.n8n_webhook_url,
|
||||
headers=headers,
|
||||
timeout=10,
|
||||
verify=False,
|
||||
params={"requestor": requestor},
|
||||
)
|
||||
_data = bool(resp.status_code == 200)
|
||||
return _data
|
||||
|
Reference in New Issue
Block a user