2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 03:55:41 +00:00

Merge branch 'master' of https://github.com/inventree/InvenTree into matmair/issue2519

This commit is contained in:
Matthias
2022-01-12 00:12:32 +01:00
22 changed files with 582 additions and 30 deletions

View File

@ -1,21 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import logging
from django.apps import AppConfig
from django.conf import settings
from maintenance_mode.core import set_maintenance_mode
from plugin import registry
logger = logging.getLogger('inventree')
class PluginAppConfig(AppConfig):
name = 'plugin'
def ready(self):
if not registry.is_loading:
# this is the first startup
registry.collect_plugins()
registry.load_plugins()
if settings.PLUGINS_ENABLED:
logger.info('Loading InvenTree plugins')
# drop out of maintenance
# makes sure we did not have an error in reloading and maintenance is still active
set_maintenance_mode(False)
if not registry.is_loading:
# this is the first startup
registry.collect_plugins()
registry.load_plugins()
# drop out of maintenance
# makes sure we did not have an error in reloading and maintenance is still active
set_maintenance_mode(False)

View File

@ -31,6 +31,10 @@ def trigger_event(event, *args, **kwargs):
and the worker will respond to it later on.
"""
if not settings.PLUGINS_ENABLED:
# Do nothing if plugins are not enabled
return
if not canAppAccessDatabase():
logger.debug(f"Ignoring triggered event '{event}' - database not ready")
return
@ -124,6 +128,8 @@ def allow_table_event(table_name):
ignore_tables = [
'common_notificationentry',
'common_webhookendpoint',
'common_webhookmessage',
]
if table_name in ignore_tables:
@ -140,6 +146,11 @@ def after_save(sender, instance, created, **kwargs):
table = sender.objects.model._meta.db_table
instance_id = getattr(instance, 'id', None)
if instance_id is None:
return
if not allow_table_event(table):
return

View File

@ -66,8 +66,9 @@ class PluginsRegistry:
"""
Load and activate all IntegrationPlugins
"""
from plugin.helpers import log_error
if not settings.PLUGINS_ENABLED:
# Plugins not enabled, do nothing
return
logger.info('Start loading plugins')
@ -76,15 +77,16 @@ class PluginsRegistry:
if not _maintenance:
set_maintenance_mode(True)
registered_sucessfull = False
registered_successful = False
blocked_plugin = None
retry_counter = settings.PLUGIN_RETRY
while not registered_sucessfull:
while not registered_successful:
try:
# We are using the db so for migrations etc we need to try this block
self._init_plugins(blocked_plugin)
self._activate_plugins()
registered_sucessfull = True
registered_successful = True
except (OperationalError, ProgrammingError):
# Exception if the database has not been migrated yet
logger.info('Database not accessible while loading plugins')
@ -123,6 +125,10 @@ class PluginsRegistry:
Unload and deactivate all IntegrationPlugins
"""
if not settings.PLUGINS_ENABLED:
# Plugins not enabled, do nothing
return
logger.info('Start unloading plugins')
# Set maintanace mode
@ -163,6 +169,10 @@ class PluginsRegistry:
Collect integration plugins from all possible ways of loading
"""
if not settings.PLUGINS_ENABLED:
# Plugins not enabled, do nothing
return
self.plugin_modules = [] # clear
# Collect plugins from paths