offload_task: log errors (#6620)

- Log any errors raised during offload_task
This commit is contained in:
Oliver 2024-03-02 18:21:45 +11:00 committed by GitHub
parent c6f43efef8
commit b19def7a1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -180,6 +180,8 @@ def offload_task(
Returns: Returns:
bool: True if the task was offloaded (or ran), False otherwise bool: True if the task was offloaded (or ran), False otherwise
""" """
from InvenTree.exceptions import log_error
try: try:
import importlib import importlib
@ -213,6 +215,7 @@ def offload_task(
return False return False
except Exception as exc: except Exception as exc:
raise_warning(f"WARNING: '{taskname}' not offloaded due to {str(exc)}") raise_warning(f"WARNING: '{taskname}' not offloaded due to {str(exc)}")
log_error('InvenTree.offload_task')
return False return False
else: else:
if callable(taskname): if callable(taskname):
@ -233,6 +236,7 @@ def offload_task(
try: try:
_mod = importlib.import_module(app_mod) _mod = importlib.import_module(app_mod)
except ModuleNotFoundError: except ModuleNotFoundError:
log_error('InvenTree.offload_task')
raise_warning( raise_warning(
f"WARNING: '{taskname}' not started - No module named '{app_mod}'" f"WARNING: '{taskname}' not started - No module named '{app_mod}'"
) )
@ -249,6 +253,7 @@ def offload_task(
if not _func: if not _func:
_func = eval(func) # pragma: no cover _func = eval(func) # pragma: no cover
except NameError: except NameError:
log_error('InvenTree.offload_task')
raise_warning( raise_warning(
f"WARNING: '{taskname}' not started - No function named '{func}'" f"WARNING: '{taskname}' not started - No function named '{func}'"
) )
@ -258,6 +263,7 @@ def offload_task(
try: try:
_func(*args, **kwargs) _func(*args, **kwargs)
except Exception as exc: except Exception as exc:
log_error('InvenTree.offload_task')
raise_warning(f"WARNING: '{taskname}' not started due to {str(exc)}") raise_warning(f"WARNING: '{taskname}' not started due to {str(exc)}")
return False return False