Skip to content

Commit

Permalink
fix events expiry commands for large number of events
Browse files Browse the repository at this point in the history
there was elastic error when from+size were over 10k
  • Loading branch information
petrjasek committed Jun 25, 2024
1 parent d06ca80 commit e6b8723
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions server/planning/commands/flag_expired_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e6b8723

Please sign in to comment.