Add code for triggering and responding to events

This commit is contained in:
Oliver 2022-01-07 21:48:17 +11:00
parent 4a5e4a88ac
commit 1e5ecb13f0

View 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