Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a monitoring function to check on the cluster #265

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/redirectioneaza/common/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.utils.translation import gettext_lazy as _
from django_q.tasks import async_task

from redirectioneaza.common.monitoring import check_queue_status

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -40,6 +42,8 @@ def async_send_email(
):
logger.info(f"Asynchronously sending {len(to_emails)} emails with subject: {subject}.")

check_queue_status()

async_task(
send_emails,
to_emails,
Expand Down
31 changes: 31 additions & 0 deletions backend/redirectioneaza/common/monitoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import logging
from typing import List

from django.conf import settings
from django_q.status import Stat
from sentry_sdk import capture_message

logger = logging.getLogger(__name__)


def check_queue_status():
try:
cluster_status: List[Stat] = Stat.get_all()

if len(cluster_status) == 0:
error_message = "No clusters found. Please check the status of the server."

logger.warning(error_message)

if settings.ENABLE_SENTRY:
capture_message(error_message, level="error")
else:
for stat in cluster_status:
if stat.task_q_size > 50:
error_message = "Too many tasks in queue. Please check the status of the server."
logger.warning(error_message)

if settings.ENABLE_SENTRY:
capture_message(error_message, level="error")
except Exception as e:
logger.error(f"Error checking task count: {e}")
Loading