From 0c51ce6e14e607e27420a9e845be7ef8408d413c Mon Sep 17 00:00:00 2001 From: Jason Peacock Date: Wed, 20 Nov 2024 12:03:54 -0600 Subject: [PATCH] Initialize events so that zenhub metrics can decrement. ZEN-35156 --- Products/ZenHub/server/events.py | 18 +++++++++--------- Products/ZenHub/server/metrics.py | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Products/ZenHub/server/events.py b/Products/ZenHub/server/events.py index 6c33cc5f91..07df019e08 100644 --- a/Products/ZenHub/server/events.py +++ b/Products/ZenHub/server/events.py @@ -73,18 +73,18 @@ class _CompletedData(_StartedData): result = attr.ib(default=_UNSPECIFIED) def __attrs_post_init__(self): - if ( - sum( - 1 - for name in ("result", "error", "retry") - if getattr(self, name) is _UNSPECIFIED - ) - != 2 - ): + unspecified = tuple( + name + for name in ("result", "error", "retry") + if getattr(self, name) is _UNSPECIFIED + ) + if len(unspecified) != 2: raise TypeError( "At least one of fields 'result', 'retry', and 'error' " - "must be specified" + "must be given an argument" ) + for name in unspecified: + object.__setattr__(self, name, None) @implementer(IServiceCallReceivedEvent) diff --git a/Products/ZenHub/server/metrics.py b/Products/ZenHub/server/metrics.py index 6130722ced..761414e3a7 100644 --- a/Products/ZenHub/server/metrics.py +++ b/Products/ZenHub/server/metrics.py @@ -97,7 +97,8 @@ def decrementLegacyMetricCounters(event): global _legacy_worklist_counters for key in (event.priority, "total"): _legacy_worklist_counters[key] -= 1 - # If the count falls below zero, there's a bug and should be logged. + # If the count falls below zero, + # there's a bug and should be logged. if _legacy_worklist_counters[key] < 0: log.warn( "Counter is negative worklist=%s value=%s",