Skip to content

Commit

Permalink
Work around silly eventengine bug
Browse files Browse the repository at this point in the history
Because:
- NAV's eventengine will not dispatch delayed alerts inside a database
  transaction, while immediate alerts are. However, the export to
  navargus occurs before the transaction is committed, which can
  result in notifications about alerts we cannot see in the database
  yet.
- The simplest workaround is to just wait a second if we cannot find
  the referenced alert.

This workaround should be removed once eventengine is fixed again.
  • Loading branch information
lunkwill42 committed Dec 11, 2020
1 parent b867164 commit 839101b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/navargus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import re
import logging
import argparse
import time
from json import JSONDecoder, JSONDecodeError
from typing import Generator, Tuple, List

Expand Down Expand Up @@ -170,11 +171,17 @@ def dispatch_alert_to_argus(alert: dict):
try:
alerthist = AlertHistory.objects.get(pk=alerthistid)
except AlertHistory.DoesNotExist:
_logger.error(
"Ignoring invalid alerthist PK received from event engine: %r",
alerthistid,
)
return
# Workaround for eventengine bug: Its transaction is potentially not
# committed yet, so we wait just a little bit:
time.sleep(1)
try:
alerthist = AlertHistory.objects.get(pk=alerthistid)
except AlertHistory.DoesNotExist:
_logger.error(
"Ignoring invalid alerthist PK received from event engine: %r",
alerthistid,
)
return

state = alert.get("state")
if state in (STATE_START, STATE_STATELESS):
Expand Down

0 comments on commit 839101b

Please sign in to comment.