-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from henrypinkard/main
Documentation progress
- Loading branch information
Showing
51 changed files
with
1,464 additions
and
499 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
.. _add_events: | ||
|
||
####################### | ||
Creating Custom Events | ||
####################### | ||
|
||
Basic Event Creation | ||
-------------------- | ||
|
||
To create a custom event: | ||
|
||
1. Subclass ``ExecutorEvent`` | ||
2. Implement the ``execute()`` method | ||
|
||
.. code-block:: python | ||
from exengine.base_classes import ExecutorEvent | ||
class MyCustomEvent(ExecutorEvent): | ||
def execute(self): | ||
# Main event logic goes here | ||
result = self.perform_operation() | ||
return result | ||
def perform_operation(self): | ||
# Implement your operation here | ||
pass | ||
Adding Notifications | ||
-------------------- | ||
|
||
To add notifications: | ||
|
||
1. Specify ``notification_types`` | ||
2. Use ``self.publish_notification()`` in ``execute()`` | ||
|
||
.. code-block:: python | ||
from exengine.notifications import MyCustomNotification | ||
class MyEventWithNotification(ExecutorEvent): | ||
notification_types = [MyCustomNotification] | ||
def execute(self): | ||
# Event logic | ||
self.publish_notification(MyCustomNotification(payload="Operation completed")) | ||
Implementing Capabilities | ||
------------------------- | ||
|
||
Data Producing Capability | ||
^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
For events that produce data: | ||
|
||
.. code-block:: python | ||
from exengine.base_classes import ExecutorEvent, DataProducing | ||
class MyDataProducingEvent(ExecutorEvent, DataProducing): | ||
def execute(self): | ||
data, metadata = self.generate_data() | ||
self.put_data(data_coordinates, data, metadata) | ||
def generate_data(self): | ||
# Generate your data here | ||
pass | ||
Stoppable Capability | ||
^^^^^^^^^^^^^^^^^^^^ | ||
|
||
For stoppable events: | ||
|
||
.. code-block:: python | ||
from exengine.base_classes import ExecutorEvent, Stoppable | ||
class MyStoppableEvent(ExecutorEvent, Stoppable): | ||
def execute(self): | ||
while not self.is_stop_requested(): | ||
self.do_work() | ||
self.cleanup() | ||
def do_work(self): | ||
# Implement your work here | ||
pass | ||
def cleanup(self): | ||
# Cleanup logic here | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.. _add_notifications: | ||
|
||
============================== | ||
Creating Custom Notifications | ||
============================== | ||
|
||
To create a custom notification: | ||
|
||
1. Subclass ``exengine.base_classes.Notification`` | ||
2. Use Python's ``@dataclass`` decorator | ||
3. Define ``category`` (from ``exengine.notifications.NotificationCategory`` enum) and ``description`` (string) as class variables | ||
4. Optionally, specify a payload type using a type hint in the class inheritance. For example, ``class MyCustomNotification(Notification[str])`` indicates this notification's payload will be a string. | ||
|
||
Keep payloads lightweight for efficient processing. Example: | ||
|
||
.. code-block:: python | ||
from dataclasses import dataclass | ||
from exengine.base_classes import Notification | ||
from exengine.notifications import NotificationCategory | ||
@dataclass | ||
class MyCustomNotification(Notification[str]): | ||
category = NotificationCategory.Device | ||
description = "A custom device status update" | ||
# Usage | ||
notification = MyCustomNotification(payload="Device XYZ is ready") | ||
Oops, something went wrong.