Fix unclear error when function is not called correctly (#19)

This commit is contained in:
Stan Triepels
2022-10-20 17:24:17 +02:00
committed by GitHub
parent 8822e7d409
commit 0aac4e7b0d
2 changed files with 7 additions and 7 deletions

View File

@@ -393,10 +393,10 @@ def monitor(result_queue: Queue, broker: Broker = None):
info_name = get_func_repr(task['func'])
if task["success"]:
# log success
logger.info(_(f"Processed {info_name} ({task['name']})"))
logger.info(_(f"Processed '{info_name}' ({task['name']})"))
else:
# log failure
logger.error(_(f"Failed {info_name} ({task['name']}) - {task['result']}"))
logger.error(_(f"Failed '{info_name}' ({task['name']}) - {task['result']}"))
logger.info(_(f"{name} stopped monitoring results"))
@@ -423,7 +423,7 @@ def worker(
# Get the function from the task
func = task["func"]
func_name = get_func_repr(func)
logger.info(_(f'{proc_name} processing {func_name} ({task["name"]})'))
logger.info(_(f"{proc_name} processing '{func_name}' ({task['name']})"))
f = task["func"]
# if it's not an instance try to get it from the string
if not callable(task["func"]):
@@ -437,12 +437,12 @@ def worker(
try:
res = f(*task["args"], **task["kwargs"])
result = (res, True)
except Exception as e:
result = (f"{e} : {traceback.format_exc()}", False)
except Exception:
result = (f"Could not process '{func_name}'. Check the location of the function and the args/kwargs.", False)
if error_reporter:
error_reporter.report()
if task.get("sync", False):
raise
raise Exception(result)
with timer.get_lock():
# Process result
task["result"] = result[0]

View File

@@ -64,7 +64,7 @@ def test_sync(broker):
@pytest.mark.django_db
def test_sync_raise_exception(broker):
with pytest.raises(TaskError):
with pytest.raises(Exception):
async_task("django_q.tests.tasks.raise_exception", broker=broker, sync=True)