diff --git a/InvenTree/plugin/builtin/integration/mixins.py b/InvenTree/plugin/builtin/integration/mixins.py index ca3af01e53..54f739d04d 100644 --- a/InvenTree/plugin/builtin/integration/mixins.py +++ b/InvenTree/plugin/builtin/integration/mixins.py @@ -102,16 +102,16 @@ class ScheduleMixin: """ if not self.has_scheduled_tasks: - raise ValueError(f"SCHEDULED_TASKS not defined") + raise ValueError("SCHEDULED_TASKS not defined") for key, task in self.scheduled_tasks.items(): - + if 'func' not in task: raise ValueError(f"Task '{key}' is missing 'func' parameter") - + if 'schedule' not in task: raise ValueError(f"Task '{key}' is missing 'schedule' parameter") - + schedule = task['schedule'].upper().strip() if schedule not in self.ALLOWABLE_SCHEDULE_TYPES: @@ -153,7 +153,6 @@ class ScheduleMixin: minutes=task.get('minutes', None), repeats=task.get('repeats', -1), ) - def unregister_tasks(self): """ diff --git a/InvenTree/plugin/registry.py b/InvenTree/plugin/registry.py index 7e08ce3efb..12dfc9d43e 100644 --- a/InvenTree/plugin/registry.py +++ b/InvenTree/plugin/registry.py @@ -299,7 +299,7 @@ class PluginsRegistry: def activate_integration_schedule(self, plugins): logger.info('Activating plugin tasks') - + from common.models import InvenTreeSetting from django_q.models import Schedule @@ -307,7 +307,7 @@ class PluginsRegistry: task_keys = [] if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_SCHEDULE'): - + for slug, plugin in plugins: if plugin.mixin_enabled('schedule'): @@ -427,7 +427,7 @@ class PluginsRegistry: """ Deactivate integration app - some magic required """ - + # unregister models from admin for plugin_path in self.installed_apps: models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed diff --git a/InvenTree/plugin/samples/integration/scheduled_task.py b/InvenTree/plugin/samples/integration/scheduled_task.py index fb84c03503..5a8f866cd7 100644 --- a/InvenTree/plugin/samples/integration/scheduled_task.py +++ b/InvenTree/plugin/samples/integration/scheduled_task.py @@ -15,6 +15,10 @@ def print_world(): print("World") +def fail_task(): + raise ValueError("This task should fail!") + + class ScheduledTaskPlugin(ScheduleMixin, IntegrationPluginBase): """ A sample plugin which provides support for scheduled tasks @@ -33,5 +37,9 @@ class ScheduledTaskPlugin(ScheduleMixin, IntegrationPluginBase): 'world': { 'func': 'plugin.samples.integration.scheduled_task.print_hello', 'schedule': 'H', - } - } \ No newline at end of file + }, + 'failure': { + 'func': 'plugin.samples.integration.scheduled_task.fail_task', + 'schedule': 'D', + }, + }