Added set_task_failed to update the task status to failure in case of
errors.
Added statement in case it's a very short task and there's no need to
wait for the ajax request.
Added get_task_result function to get the result of the task