Skip to content

Commit

Permalink
Refine logger import in notifier service to prevent circular import e…
Browse files Browse the repository at this point in the history
…rror

The logger import, previously happening at the top of the 'notifier.py' file, is now specified within each individual notification function (_telegram, _telegram_errors, _discord, _slack). This change allows for more specific use and control of the logger within each isolated method.
  • Loading branch information
saleh-mir committed Dec 18, 2023
1 parent 7898fd2 commit a54cde2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion jesse/services/notifier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests
from jesse.services.env import ENV_VALUES
from jesse.services import logger
import jesse.helpers as jh
from timeloop import Timeloop
from datetime import timedelta
Expand Down Expand Up @@ -67,6 +66,8 @@ def notify_urgently(msg: str) -> None:


def _telegram(msg: str) -> None:
from jesse.services import logger

token = ENV_VALUES['GENERAL_TELEGRAM_BOT_TOKEN']
chat_id: int = ENV_VALUES['GENERAL_TELEGRAM_BOT_CHAT_ID']

Expand All @@ -87,6 +88,8 @@ def _telegram(msg: str) -> None:


def _telegram_errors(msg: str) -> None:
from jesse.services import logger

token = ENV_VALUES['ERROR_TELEGRAM_BOT_TOKEN']
chat_id: int = ENV_VALUES['ERROR_TELEGRAM_BOT_CHAT_ID']

Expand All @@ -107,6 +110,8 @@ def _telegram_errors(msg: str) -> None:


def _discord(msg: str, webhook_address=None) -> None:
from jesse.services import logger

if webhook_address is None:
webhook_address = ENV_VALUES['GENERAL_DISCORD_WEBHOOK']

Expand All @@ -125,6 +130,8 @@ def _discord(msg: str, webhook_address=None) -> None:


def _slack(msg: str, webhook_address=None) -> None:
from jesse.services import logger

if webhook_address is None:
webhook_address = ENV_VALUES['GENERAL_SLACK_WEBHOOK'] if 'GENERAL_SLACK_WEBHOOK' in ENV_VALUES else ''

Expand Down

0 comments on commit a54cde2

Please sign in to comment.