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