From 0aac4e7b0d1aeedc3c1c77a13f27dd6d7619d962 Mon Sep 17 00:00:00 2001 From: Stan Triepels <1939656+GDay@users.noreply.github.com> Date: Thu, 20 Oct 2022 17:24:17 +0200 Subject: [PATCH] Fix unclear error when function is not called correctly (#19) --- django_q/cluster.py | 12 ++++++------ django_q/tests/test_cluster.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index 8a9046a..7382944 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -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] diff --git a/django_q/tests/test_cluster.py b/django_q/tests/test_cluster.py index 0e5aee8..57500ec 100644 --- a/django_q/tests/test_cluster.py +++ b/django_q/tests/test_cluster.py @@ -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)