def METHOD_NAME(scan_id, reason=None):
    """analysis didn't finish successfully, so process it appropriately"""
    scan = Scan.objects.get(id=scan_id)
    scan.set_state(SCAN_STATES['FAILED'])
    if scan.is_errata_scan():
        scan.enabled = False
        # set last successfully finished scan as enabled
        scan.enable_last_successfull()
    scan.save()
    if reason:
        Task.objects.filter(id=scan.scanbinding.task.id).update(
            result="Scan failed due to: %s" % reason)
    if scan.is_errata_base_scan():
        METHOD_NAME(scan.scanbinding.task.parent.scanbinding.scan.id, "Bask scan failed")