def AbandonTask(modal):
    """
    当预处理出现错误时,放弃该任务,释放服务器,等待用户手动删除该visit
    :param modalID: 与visit相关的所有task,包括静态和动态脑连接计算task
    :return:
    """
    logging.info('\033[1;33m ---------------------Going to Abandon this Causality task-------------------- \033[0m')
    # print('\033[0;35;46m ---------------------Going to Abandon this Causality task-------------------- \033[0m')
    tasks = CausalityConnectivityTask.objects.filter(Task_Modal=modal)

    if len(tasks):
        server = tasks[0].Task_Server
        for eachTask in tasks:
            eachTask.Task_Start = True
            eachTask.Task_Finish = True
            eachTask.Task_Status = -1
            # eachTask.Task_Server = None
            eachTask.save()

        if server:
            isDebug = TaskQueue.objects.get(Type='CausalityConnectivity').isDebug
            if not isDebug:
                SSHCommand.CleanUpCausalityServer(server)
            # SSHCommand.RestartServer(server)
            server.Server_IsBusy = False
            server.save()
def onFinishedPreprocessingTask(task):
    """
    任务结束后,拷贝数据,并删除文件夹,释放服务器
    :param task:
    :return:
    """
    status = 500
    SSHCommand.onFinishTaskInSSH(task)
    task.Task_Finish = True
    task.Progress_value = 100
    task.Task_EndTime = timezone.now()
    task.save()

    ServerManagement.PopAvailableServer(task.Task_Server)
    SSHCommand.CleanUpCausalityServer(task.Task_Server)
    # SSHCommand.RestartServer(task.Task_Server)
    status = 200
    return status