It seems django-q doesn't detect error for unknown raison.
And task.success always return true even failure. It sound like
whatever is happening no error is raised. Shouldn't I get the exception error in the console or in the webpage?
Expected: When an error to achieve a task, task.success should be False. So the else block of my hook function wile be executed.
Hook function:
def str_hook(task):
"""Hook for async task that return a string."""
asynchrone_task = AsynchroneTask.objects.get(id=task.id)
asynchrone_task.time_taken = timedelta(seconds=task.time_taken())
asynchrone_task.result = str(task.result)
if task.success:
asynchrone_task.status = AsynchroneTask.FINISHED
else:
asynchrone_task.status = AsynchroneTask.FAILED
asynchrone_task.save()
offload task:
def upload_io_real_spents(request):
batch_name = get_object_or_404(BatchName,
pk="00000000-0000-0000-0000-000000000001")
file_path = settings.IMPORTS_PATH + 'dbm.csv'
task_id = async_task(
task_upload_io_real_spents,
file_path,
hook=q_services.str_hook,
)
try:
asynchrone_task = AsynchroneTask(
id=task_id,
title= 'Importing Consolidated DSPs data',
dsp=batch_name,
user=request.user
)
except Exception as e:
messages.error(request, e.__cause__)
return redirect("imports")
else:
asynchrone_task.save()
asynchrone_task.save()
messages.success(request, "Task successfully started.")
return redirect('imports')