Skip to content

Commit cac3ba7

Browse files
authored
fix: add should_handle callback for opt out filters (#589)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed
1 parent 0516bc9 commit cac3ba7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/codegen/extensions/events/linear.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def unsubscribe_all_handlers(self):
5555
for handler in self.registered_handlers:
5656
self.unsubscribe_handler_to_webhook(self.registered_handlers[handler])
5757

58-
def event(self, event_name):
58+
def event(self, event_name, should_handle: Callable[[dict], bool] | None = None):
5959
"""Decorator for registering an event handler.
6060
6161
:param event_name: The name of the event to handle.
@@ -71,7 +71,12 @@ def decorator(func):
7171

7272
@functools.wraps(func)
7373
def wrapper(*args, **kwargs):
74-
return func(*args, **kwargs)
74+
should_handle_result = should_handle(*args, **kwargs) if should_handle else True
75+
if should_handle is None or should_handle_result:
76+
return func(*args, **kwargs)
77+
else:
78+
logger.info(f"Skipping event {event_name} for {func_name}")
79+
return None
7580

7681
return wrapper
7782

0 commit comments

Comments
 (0)