def check_cancel_task(self, task):
    """
    Check if a task was cancelled or has thrown an error. If so, end this task and don't
    call any callbacks, which are usually future signatures in a chain.
    We refresh the model view since if the model status was set to "CANCELLED"
    by Django (apps.dc_algorithm.views.CancelRequest.get()), its view in
    Celery workers may not reflect the relational backing.

    Returns True if the task is cancelled and the calling code should `return`.

    Parameters
    ---------
    self: celery.app.task
        A Celery task instance to cancel processing for.
    task: app-specific task ORM object
        A view of an app's task entry in the Django database.
        `apps.custom_mosaic_tool.models.CustomMosaicToolTask` is one example.
    """
    if task.status in ['CANCELLED', 'ERROR']:
        self.request.chain = None
        return True
    else: # The model view may be outdated, so refresh and check again.
        task.refresh_from_db()
        if task.status in ['CANCELLED', 'ERROR']:
            self.request.chain = None
            return True
        return False