mirror of
https://github.com/inventree/inventree-docs.git
synced 2025-04-29 06:06:51 +00:00
Add documentation for "events" mixin
This commit is contained in:
parent
836b5bc741
commit
2f479b5d4e
@ -1,3 +1,36 @@
|
|||||||
---
|
---
|
||||||
title: Event Mixin
|
title: Event Mixin
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## EventMixin
|
||||||
|
|
||||||
|
The `EventMixin` class enables plugins to respond to certain triggered events.
|
||||||
|
|
||||||
|
When a certain (server-side) event occurs, the background worker passes the event information to any plugins which inherit from the `EventMixin` base class.
|
||||||
|
|
||||||
|
Implementing classes must provide a `process_event` function:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class EventPlugin(EventMixin, IntegrationPluginBase):
|
||||||
|
"""
|
||||||
|
A simple example plugin which responds to events on the InvenTree server.
|
||||||
|
|
||||||
|
This example simply prints out the event information.
|
||||||
|
A more complex plugin could respond to specific events however it wanted.
|
||||||
|
"""
|
||||||
|
|
||||||
|
PLUGIN_NAME = "EventPlugin"
|
||||||
|
PLUGIN_SLUG = "event"
|
||||||
|
PLUGIN_TITLE = "Triggered Events"
|
||||||
|
|
||||||
|
def process_event(self, event, *args, **kwargs):
|
||||||
|
print(f"Processing triggered event: '{event}'")
|
||||||
|
```
|
||||||
|
|
||||||
|
### Events
|
||||||
|
|
||||||
|
Events are passed through using a string identifier, e.g. 'build.completed'
|
||||||
|
|
||||||
|
The arguments (and keyword arguments) passed to the receiving function depend entirely on the type of event.
|
||||||
|
|
||||||
|
Implementing a response to a particular event requires a working knowledge of the InvenTree code base, especially related to that event being received.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user