def onFinishedPreprocessingTask(task):
    status = 500
    SSHCommand.onFinishParcellationAndCorrelationinSSH(task)
    task.Task_Finish = True
    task.Progress_value = 100
    task.Task_EndTime = timezone.now()
    task.save()
    ServerManagement.PopAvailableServer(task.Task_Server)
    if task.Preprocess_Type == 'Static':
        preprocessTaskList = CorrelationConnectivityTask.objects.filter(Task_Modal=task.Task_Modal,
                                                                        Preprocess_Type='Dynamic')
        taskDynamic = preprocessTaskList[0]
        taskDynamic.Task_Server = task.Task_Server
        taskDynamic.save()
        check_and_submitTask(taskPrefer=taskDynamic)

        # create Causality Task
    elif task.Preprocess_Type == 'Dynamic':
        taskTMP = CausalityConnectivityTask.objects.filter(Task_Modal=task.Task_Modal)
        if not len(taskTMP):
            causalityTask = CausalityConnectivityTask.objects.create(Task_Modal=task.Task_Modal, Task_Status=200,
                                                                 Task_Type='Causality',
                                                                 Preprocessed_Dir=task.Preprocessed_Dir)
            causalityTask.save()
        isDebug = TaskQueue.objects.get(Type='CorrelationConnectivity').isDebug
        if not isDebug:
            SSHCommand.CleanUpParcellationServer(task.Task_Server)
        SSHCommand.RestartServer(task.Task_Server)

    status = 200
    return status
Ejemplo n.º 2
0
def ResetPreprocessingTask(request, ModalID):
    if not request.session.get('is_login', None):
        return HttpResponse('Please login in first')

    TasksToReset = CorrelationConnectivityTask.objects.filter(Task_Modal_id=ModalID)
    if len(TasksToReset):
        Server = TasksToReset[0].Task_Server
        if Server:
            servers_occupied = CorrelationConnectivityTask.objects.filter(Task_Server=Server).filter(Task_Start=1,
                                                                                                     Task_Finish=0)
            if len(servers_occupied) == 1:

                if servers_occupied[0] == TasksToReset[0]:
                    # print('Only One server occupied, can be reset ' + Server.Server_IP)
                    # print('Going to reset' + Server.Server_IP)
                    isDebug = TaskQueue.objects.get(Type='CorrelationConnectivity').isDebug
                    if not isDebug:
                        SSHCommand.CleanUpParcellationServer(Server)  # 可能清除掉动态脑连接预处理文件目录,谨慎使用
                    SSHCommand.RestartServer(Server)
                    Server.Server_IsBusy = False
                    Server.save()
        for task in TasksToReset:
            task.Progress_value = 0
            task.Task_Status = 200
            task.Task_Server = None
            task.Task_Finish = 0
            task.Task_Start = 0
            task.save()

    return HttpResponse('Task Reset successfully')