Support nested filters on event hooks definitions #251

Closed
opened 2023-04-25 10:54:56 +02:00 by blacklight · 0 comments
Owner

Event hooks support key-value pairs for event attributes matching, and currently those pairs need to be strictly matching the associated key-value on the event for the hook to trigger.

We'd also like to support hook matching on more complex objects. For example, an entity object with several nested attributes:

from platypush.event.hook import hook
from platypush.message.event.entities import EntityUpdateEvent

@hook(EntityUpdateEvent, entity={
  'plugin': 'system',
  'external_id': 'system:cpu:percent',
})
def on_new_cpu_percent(event: EntityUpdateEvent):
  ...

The above hook would trigger for any EntityUpdateEvent that has an entity argument with the specified nested values for plugin and external_id, regardless of its other attributes.

Event hooks support key-value pairs for event attributes matching, and currently those pairs need to be strictly matching the associated key-value on the event for the hook to trigger. We'd also like to support hook matching on more complex objects. For example, an entity object with several nested attributes: ```python from platypush.event.hook import hook from platypush.message.event.entities import EntityUpdateEvent @hook(EntityUpdateEvent, entity={ 'plugin': 'system', 'external_id': 'system:cpu:percent', }) def on_new_cpu_percent(event: EntityUpdateEvent): ... ``` The above hook would trigger for any `EntityUpdateEvent` that has an `entity` argument with the specified nested values for `plugin` and `external_id`, regardless of its other attributes.
blacklight added the
enhancement
label 2023-04-25 10:54:56 +02:00
blacklight self-assigned this 2023-04-25 10:54:56 +02:00
blacklight added this to the core project 2023-04-25 10:54:56 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: platypush/platypush#251
No description provided.