mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Add code for triggering and responding to events
This commit is contained in:
		
							
								
								
									
										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 | ||||
		Reference in New Issue
	
	Block a user