From 73db5d11ac6388ef6fb1c04c79cade539901067f Mon Sep 17 00:00:00 2001 From: Alex Dehnert Date: Sat, 20 Apr 2024 18:32:37 +0000 Subject: [PATCH] Add punt hook to drop admin-chosen messages Useful if there's a class with some useful messages, but also a high rate of messages that nobody needs to see that unnecessarily load the server. --- roost_backend/subscribers.py | 5 +++++ roost_ng/settings/roost.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/roost_backend/subscribers.py b/roost_backend/subscribers.py index 377da81..635e469 100644 --- a/roost_backend/subscribers.py +++ b/roost_backend/subscribers.py @@ -18,6 +18,7 @@ from django.core.exceptions import AppRegistryNotReady from django.db import IntegrityError, transaction from django.db.models import Q +from django.conf import settings from djangorestframework_camel_case.util import underscoreize import setproctitle import zephyr @@ -235,6 +236,10 @@ async def zephyr_handler(self): if notice.opcode.lower() == b'ping': # Ignoring pings continue + if settings.ROOST_CHECK_PUNT(notice): + _LOGGER.getChild('punt').info("[%s] zephyr handler punting znotice %s, %s", + self.log_prefix, notice, notice.__dict__) + continue # This appears to be an incoming message. msg = django.apps.apps.get_model('roost_backend', 'Message').from_notice(notice) _LOGGER.debug('%s', msg) diff --git a/roost_ng/settings/roost.py b/roost_ng/settings/roost.py index 4ad3268..1c0c130 100644 --- a/roost_ng/settings/roost.py +++ b/roost_ng/settings/roost.py @@ -13,3 +13,13 @@ # Making this operator tweakable so we can experiment. # JS roost had a 100 message limit. Snipe asked for 128 messages. ROOST_MESSAGES_MAX_LIMIT = cfg.get('message_max_limit', 128) + +def ROOST_CHECK_PUNT(znotice): + """Hook to optionally drop certain messages before adding to DB + + Useful if there's a class with some useful messages, but also a high + rate of messages that nobody needs to see that unnecessarily load the + server. + + Returns a bool indicating whether or not to punt a message.""" + return False