Skip to content

Commit

Permalink
update sr3 event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Feb 14, 2025
1 parent 936bc47 commit 1dd3e46
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions msc_pygeoapi/event/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# <[email protected]>
# Etienne Pelletier <[email protected]>
#
# Copyright (c) 2021 Tom Kralidis
# Copyright (c) 2025 Tom Kralidis
# Copyright (c) 2024 Louis-Philippe Rousseau-Lambert
# Copyright (c) 2024 Etienne Pelletier
#
Expand All @@ -31,6 +31,7 @@
# OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================

import logging

from sarracenia.flowcb import FlowCB
Expand All @@ -40,17 +41,18 @@

class EventBase(FlowCB):

def process_messages(self, worklist) -> bool:
def process_message(self, worklist, worklist_type) -> bool:
"""
Process messages from the worklist
Process sarracenia message
:param worklist: `sarracenia.flow.worklist`
:returns: `bool`
"""

for msg in worklist.incoming:
new_msgs = []

for msg in getattr(worklist, worklist_type):
try:
from msc_pygeoapi.handler.core import CoreHandler

Expand All @@ -59,11 +61,14 @@ def process_messages(self, worklist) -> bool:
handler = CoreHandler(filepath)
result = handler.handle()
LOGGER.debug(f'Result: {result}')
new_msgs.append(msg)
except Exception as err:
LOGGER.error(f'Error handling message: {err}')
worklist.failed.append(msg)
return False

setattr(worklist, worklist_type, new_msgs)

return True


Expand All @@ -77,7 +82,8 @@ def after_work(self, worklist) -> None:
:returns: `bool`
"""
return self.process_messages(worklist)

return self.process_message(worklist, 'ok')


class EventAfterAccept(EventBase):
Expand All @@ -90,4 +96,5 @@ def after_accept(self, worklist) -> None:
:returns: `bool`
"""
return self.process_messages(worklist)

return self.process_message(worklist, 'incoming')

0 comments on commit 1dd3e46

Please sign in to comment.