From e6b8723b2df5a870764de82e7a68f27df7f96476 Mon Sep 17 00:00:00 2001 From: Petr Jasek Date: Tue, 25 Jun 2024 14:36:02 +0200 Subject: [PATCH] fix events expiry commands for large number of events there was elastic error when from+size were over 10k --- server/planning/commands/flag_expired_items.py | 9 +++++++-- server/planning/events/events.py | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/planning/commands/flag_expired_items.py b/server/planning/commands/flag_expired_items.py index 61136cf03..038125b6f 100644 --- a/server/planning/commands/flag_expired_items.py +++ b/server/planning/commands/flag_expired_items.py @@ -8,6 +8,8 @@ # AUTHORS and LICENSE files distributed with this source code, or # at https://www.sourcefabric.org/superdesk/license +import superdesk.errors + from flask import current_app as app from superdesk import Command, command, get_resource_service from superdesk.logging import logger @@ -92,8 +94,11 @@ def _flag_expired_events(self, expiry_datetime): elif self._get_event_schedule(event) > expiry_datetime: events_in_use.add(event_id) else: - events_expired.add(event_id) - events_service.system_update(event_id, {"expired": True}, event) + try: + events_service.system_update(event_id, {"expired": True}, event) + events_expired.add(event_id) + except superdesk.errors.SuperdeskApiError: + pass for plan in event.get("_plans", []): plan_id = plan[config.ID_FIELD] planning_service.system_update(plan_id, {"expired": True}, plan) diff --git a/server/planning/events/events.py b/server/planning/events/events.py index 62b80fa02..49a4c3d45 100644 --- a/server/planning/events/events.py +++ b/server/planning/events/events.py @@ -779,6 +779,10 @@ def get_expired_items(self, expiry_datetime, spiked_events_only=False): while True: query["from"] = total_received + if query["from"] + query["size"] > 10000: + # Prevent elastic error + break + results = self.search(query) # If the total_events has not been set, then this is the first query