'Update InstructorTask object corresponding to this task with info about failure.
Fetches and updates exception and traceback information on failure.
If an exception is raised internal to the task, it is caught by celery and provided here.
The information is recorded in the InstructorTask object as a JSON-serialized dict
stored in the task_output column.  It contains the following keys:
\'exception\':  type of exception object
\'message\': error message from exception object
\'traceback\': traceback information (truncated if necessary)
Note that there is no way to record progress made within the task (e.g. attempted,
succeeded, etc.) when such failures occur.'

def on_failure(self, exc, task_id, args, kwargs, einfo):

    TASK_LOG.debug(u'Task    %s:    failure    returned', task_id)
    entry_id = args[0]
    try:
        entry = InstructorTask.objects.get(pk=entry_id)
    except InstructorTask.DoesNotExist:
        TASK_LOG.error(u'Task    (%s)    has    no    InstructorTask    object    for    id    %s', task_id, entry_id)
    else:
        TASK_LOG.warning(u'Task    (%s)    failed', task_id, exc_info=True)
        entry.task_output = InstructorTask.create_output_for_failure(einfo.exception, einfo.traceback)
        entry.task_state = FAILURE
        entry.save_now()
