From f5a216451abb044feae83e1d8eca1b93d6c9b3cc Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 2 Feb 2023 23:36:19 +1100 Subject: [PATCH] Plugin schedule fix (#4295) * Cleanup old info message (seems out of place) * Wrap called function in quotes - Doesn't work if you pass the function object itself * Fix path to called method This must have been broken for a while? --- InvenTree/plugin/apps.py | 3 --- InvenTree/plugin/base/integration/mixins.py | 5 +++-- InvenTree/plugin/samples/integration/scheduled_task.py | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/InvenTree/plugin/apps.py b/InvenTree/plugin/apps.py index 28f1acac8e..e17d96bd06 100644 --- a/InvenTree/plugin/apps.py +++ b/InvenTree/plugin/apps.py @@ -53,6 +53,3 @@ class PluginAppConfig(AppConfig): if not registry.git_is_modern: # pragma: no cover # simulating old git seems not worth it for coverage log_error(_('Your environment has an outdated git version. This prevents InvenTree from loading plugin details.'), 'load') - - else: - logger.info("Plugins not enabled - skipping loading sequence") # pragma: no cover diff --git a/InvenTree/plugin/base/integration/mixins.py b/InvenTree/plugin/base/integration/mixins.py index 5818381fdd..0e2279d7cc 100644 --- a/InvenTree/plugin/base/integration/mixins.py +++ b/InvenTree/plugin/base/integration/mixins.py @@ -12,7 +12,6 @@ import InvenTree.helpers from plugin.helpers import (MixinImplementationError, MixinNotImplementedError, render_template, render_text) from plugin.models import PluginConfig, PluginSetting -from plugin.registry import registry from plugin.urls import PLUGIN_BASE logger = logging.getLogger('inventree') @@ -153,12 +152,14 @@ class ScheduleMixin: for key, task in self.scheduled_tasks.items(): task_name = self.get_task_name(key) + obj = { 'name': task_name, 'schedule_type': task['schedule'], 'minutes': task.get('minutes', None), 'repeats': task.get('repeats', -1), } + func_name = task['func'].strip() if '.' in func_name: @@ -167,7 +168,7 @@ class ScheduleMixin: else: """Non-dotted notation indicates that we wish to call a 'member function' of the calling plugin. This is managed by the plugin registry itself.""" slug = self.plugin_slug() - obj['func'] = registry.call_plugin_function + obj['func'] = 'plugin.registry.call_plugin_function' obj['args'] = f"'{slug}', '{func_name}'" if Schedule.objects.filter(name=task_name).exists(): diff --git a/InvenTree/plugin/samples/integration/scheduled_task.py b/InvenTree/plugin/samples/integration/scheduled_task.py index 101a2e3687..50c7fd8d97 100644 --- a/InvenTree/plugin/samples/integration/scheduled_task.py +++ b/InvenTree/plugin/samples/integration/scheduled_task.py @@ -27,6 +27,7 @@ class ScheduledTaskPlugin(ScheduleMixin, SettingsMixin, InvenTreePlugin): NAME = "ScheduledTasksPlugin" SLUG = "schedule" TITLE = "Scheduled Tasks" + VERSION = "0.2.0" SCHEDULED_TASKS = { 'member': {