From 254efd23077e6d9c4afb3267ec9933fa93847ee8 Mon Sep 17 00:00:00 2001 From: thriuin Date: Wed, 17 Apr 2024 15:25:58 -0400 Subject: [PATCH] OPEN-3194: Remove frequent common Events generated by the open data portal using a background task --- search/tasks.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/search/tasks.py b/search/tasks.py index eddab00..1e8c893 100644 --- a/search/tasks.py +++ b/search/tasks.py @@ -87,3 +87,14 @@ def save_search_logs_to_file(): log_writer.writerow(log_entry) log.delete() logger.info(f'{older_logs.count()} log entries purged.') + + +@shared_task() +def purge_search_info_events(): + + logger = logging.getLogger(__name__) + + one_hour_ago = datetime.today() - timedelta(hours=1) + old_ckan_events = Event.objects.filter(log_timestamp__lte=one_hour_ago, component_id='data_import_ckan_json.remote', category='success') + for event in old_ckan_events: + event.delete()