From 414ea00b6d7d4fbc7cbb96e45d414f3c19a8c595 Mon Sep 17 00:00:00 2001 From: Sunandadadi Date: Tue, 9 Jul 2024 16:21:53 -0400 Subject: [PATCH] [redhat-3.12] events: Expose notification rerun time interval in a variable (PROJQUAY-7441) (#3012) --- util/config/schema.py | 5 +++++ util/notification.py | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/util/config/schema.py b/util/config/schema.py index d295bc98a..ab787c187 100644 --- a/util/config/schema.py +++ b/util/config/schema.py @@ -1553,5 +1553,10 @@ CONFIG_SCHEMA = { }, }, }, + "NOTIFICATION_TASK_RUN_MINIMUM_INTERVAL_MINUTES": { + "type": "number", + "description": "Interval in minutes that defines frequency to re-run notifications", + "x-example": 5000, + }, }, } diff --git a/util/notification.py b/util/notification.py index 10852a831..e2a2a8f12 100644 --- a/util/notification.py +++ b/util/notification.py @@ -1,6 +1,7 @@ import json import logging +from app import app from data.database import ( ExternalNotificationEvent, RepositoryNotification, @@ -21,11 +22,13 @@ BATCH_SIZE = 10 # since we test with mysql 5.7 which does not support this flag. SKIP_LOCKED = True +# interval in minutes that specifies how long a task must wait before being run again, defaults to 5hrs +NOTIFICATION_TASK_RUN_MINIMUM_INTERVAL_MINUTES = app.config.get( + "NOTIFICATION_TASK_RUN_MINIMUM_INTERVAL_MINUTES", 5 * 60 +) -def fetch_active_notification(event, task_run_interval_ms=5 * 60 * 60 * 1000): - """ - task_run_interval_ms specifies how long a task must wait before being ran again. - """ + +def fetch_active_notification(event): with db_transaction(): try: # Fetch active notifications that match the event_name @@ -41,7 +44,8 @@ def fetch_active_notification(event, task_run_interval_ms=5 * 60 * 60 * 1000): RepositoryNotification.number_of_failures < 3, ( RepositoryNotification.last_ran_ms - < get_epoch_timestamp_ms() - task_run_interval_ms + < get_epoch_timestamp_ms() + - (NOTIFICATION_TASK_RUN_MINIMUM_INTERVAL_MINUTES * 60 * 1000) ) | (RepositoryNotification.last_ran_ms.is_null(True)), )