2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Add a task which fails on purpose

This commit is contained in:
Oliver Walters 2022-01-07 17:04:33 +11:00
parent 36feef6558
commit c04e07c1fa
3 changed files with 17 additions and 10 deletions

View File

@ -102,16 +102,16 @@ class ScheduleMixin:
""" """
if not self.has_scheduled_tasks: 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(): for key, task in self.scheduled_tasks.items():
if 'func' not in task: if 'func' not in task:
raise ValueError(f"Task '{key}' is missing 'func' parameter") raise ValueError(f"Task '{key}' is missing 'func' parameter")
if 'schedule' not in task: if 'schedule' not in task:
raise ValueError(f"Task '{key}' is missing 'schedule' parameter") raise ValueError(f"Task '{key}' is missing 'schedule' parameter")
schedule = task['schedule'].upper().strip() schedule = task['schedule'].upper().strip()
if schedule not in self.ALLOWABLE_SCHEDULE_TYPES: if schedule not in self.ALLOWABLE_SCHEDULE_TYPES:
@ -153,7 +153,6 @@ class ScheduleMixin:
minutes=task.get('minutes', None), minutes=task.get('minutes', None),
repeats=task.get('repeats', -1), repeats=task.get('repeats', -1),
) )
def unregister_tasks(self): def unregister_tasks(self):
""" """

View File

@ -299,7 +299,7 @@ class PluginsRegistry:
def activate_integration_schedule(self, plugins): def activate_integration_schedule(self, plugins):
logger.info('Activating plugin tasks') logger.info('Activating plugin tasks')
from common.models import InvenTreeSetting from common.models import InvenTreeSetting
from django_q.models import Schedule from django_q.models import Schedule
@ -307,7 +307,7 @@ class PluginsRegistry:
task_keys = [] task_keys = []
if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_SCHEDULE'): if settings.PLUGIN_TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_SCHEDULE'):
for slug, plugin in plugins: for slug, plugin in plugins:
if plugin.mixin_enabled('schedule'): if plugin.mixin_enabled('schedule'):
@ -427,7 +427,7 @@ class PluginsRegistry:
""" """
Deactivate integration app - some magic required Deactivate integration app - some magic required
""" """
# unregister models from admin # unregister models from admin
for plugin_path in self.installed_apps: for plugin_path in self.installed_apps:
models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed

View File

@ -15,6 +15,10 @@ def print_world():
print("World") print("World")
def fail_task():
raise ValueError("This task should fail!")
class ScheduledTaskPlugin(ScheduleMixin, IntegrationPluginBase): class ScheduledTaskPlugin(ScheduleMixin, IntegrationPluginBase):
""" """
A sample plugin which provides support for scheduled tasks A sample plugin which provides support for scheduled tasks
@ -33,5 +37,9 @@ class ScheduledTaskPlugin(ScheduleMixin, IntegrationPluginBase):
'world': { 'world': {
'func': 'plugin.samples.integration.scheduled_task.print_hello', 'func': 'plugin.samples.integration.scheduled_task.print_hello',
'schedule': 'H', 'schedule': 'H',
} },
} 'failure': {
'func': 'plugin.samples.integration.scheduled_task.fail_task',
'schedule': 'D',
},
}