mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-05 06:08:12 +08:00
Fix unclear error when function is not called correctly (#19)
This commit is contained in:
+6
-6
@@ -393,10 +393,10 @@ def monitor(result_queue: Queue, broker: Broker = None):
|
|||||||
info_name = get_func_repr(task['func'])
|
info_name = get_func_repr(task['func'])
|
||||||
if task["success"]:
|
if task["success"]:
|
||||||
# log success
|
# log success
|
||||||
logger.info(_(f"Processed {info_name} ({task['name']})"))
|
logger.info(_(f"Processed '{info_name}' ({task['name']})"))
|
||||||
else:
|
else:
|
||||||
# log failure
|
# 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"))
|
logger.info(_(f"{name} stopped monitoring results"))
|
||||||
|
|
||||||
|
|
||||||
@@ -423,7 +423,7 @@ def worker(
|
|||||||
# Get the function from the task
|
# Get the function from the task
|
||||||
func = task["func"]
|
func = task["func"]
|
||||||
func_name = get_func_repr(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"]
|
f = task["func"]
|
||||||
# if it's not an instance try to get it from the string
|
# if it's not an instance try to get it from the string
|
||||||
if not callable(task["func"]):
|
if not callable(task["func"]):
|
||||||
@@ -437,12 +437,12 @@ def worker(
|
|||||||
try:
|
try:
|
||||||
res = f(*task["args"], **task["kwargs"])
|
res = f(*task["args"], **task["kwargs"])
|
||||||
result = (res, True)
|
result = (res, True)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
result = (f"{e} : {traceback.format_exc()}", False)
|
result = (f"Could not process '{func_name}'. Check the location of the function and the args/kwargs.", False)
|
||||||
if error_reporter:
|
if error_reporter:
|
||||||
error_reporter.report()
|
error_reporter.report()
|
||||||
if task.get("sync", False):
|
if task.get("sync", False):
|
||||||
raise
|
raise Exception(result)
|
||||||
with timer.get_lock():
|
with timer.get_lock():
|
||||||
# Process result
|
# Process result
|
||||||
task["result"] = result[0]
|
task["result"] = result[0]
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ def test_sync(broker):
|
|||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_sync_raise_exception(broker):
|
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)
|
async_task("django_q.tests.tasks.raise_exception", broker=broker, sync=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user