mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add code for triggering and responding to events
This commit is contained in:
parent
4a5e4a88ac
commit
1e5ecb13f0
42
InvenTree/InvenTree/events.py
Normal file
42
InvenTree/InvenTree/events.py
Normal file
@ -0,0 +1,42 @@
|
||||
"""
|
||||
Functions for triggering and responding to server side events
|
||||
"""
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
from InvenTree.tasks import offload_task
|
||||
|
||||
|
||||
logger = logging.getLogger('inventree')
|
||||
|
||||
|
||||
def trigger_event(event, *args, **kwargs):
|
||||
"""
|
||||
Trigger an even with optional arguments.
|
||||
|
||||
This event will be stored in the database,
|
||||
and the worker will respond to it later on.
|
||||
"""
|
||||
|
||||
logger.debug(f"Event triggered: '{event}'")
|
||||
|
||||
offload_task(
|
||||
'InvenTree.events.process_event',
|
||||
event,
|
||||
*args,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def process_event(event, *args, **kwargs):
|
||||
"""
|
||||
Respond to a triggered event.
|
||||
|
||||
This function is run by the background worker process.
|
||||
"""
|
||||
|
||||
logger.info(f"Processing event '{event}'")
|
||||
|
||||
# Determine if there are any plugins which are interested in responding
|
Loading…
Reference in New Issue
Block a user