Skip to content

Commit

Permalink
interval from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sentax committed May 20, 2024
1 parent 27d8eca commit ad3bdb7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions brightIDfaucet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def str2bool(v):
TELEGRAM_CHANNEL_ID = os.environ.get("TELEGRAM_CHANNEL_ID")
TELEGRAM_API_TOKEN = os.environ.get("TELEGRAM_API_TOKEN")


assert DEPLOYMENT_ENV in ["dev", "main"]


Expand Down Expand Up @@ -264,3 +265,5 @@ def before_send(event, hint):
),
}
CELERY_BROKER_URL = REDIS_URL

TELEGRAM_MIN_LOG_INTERVAL = 10 # seconds
3 changes: 2 additions & 1 deletion core/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

API_TOKEN = settings.TELEGRAM_API_TOKEN
CHANNEL_ID = settings.TELEGRAM_CHANNEL_ID
MIN_INTERVAL = settings.TELEGRAM_MIN_LOG_INTERVAL


BASE_URL = f"https://api.telegram.org/bot{API_TOKEN}"
Expand All @@ -27,7 +28,7 @@ def send_telegram_log(text):


log_cache = defaultdict(int)
MIN_INTERVAL = 10



class LogMiddleware(MiddlewareMixin):
Expand Down
7 changes: 5 additions & 2 deletions core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

from django.test import TestCase
from core.telegram import LogMiddleware
from django.conf import settings

TELEGRAM_MIN_LOG_INTERVAL = settings.TELEGRAM_MIN_LOG_INTERVAL

from .constraints import (
Attest,
Expand Down Expand Up @@ -314,8 +317,8 @@ def test_log_message_sent_to_telegram(self):
self.assertEqual(res['ok'], True)
res = self.middleware.log_message("Test log message")
self.assertEqual(res['ok'], False)
# delay 11 seconds
time.sleep(11)
# delay
time.sleep(TELEGRAM_MIN_LOG_INTERVAL)
res = self.middleware.log_message("Test log message")
self.assertEqual(res['ok'], True)
res = self.middleware.log_message("Test log message")
Expand Down

0 comments on commit ad3bdb7

Please sign in to comment.