Ejemplo n.º 1
0
//根据状态插入到相应队列中
void VC::PushTask(const TaskPtr& task) {
    TaskState ts = task->GetTaskState(); 
    assert(ts == TASK_WAIT || ts == TASK_RUN);
    if(ts == TASK_WAIT) 
        m_wait_queue.PushBack(task);
    else 
        m_run_queue.PushBack(task);
}
Ejemplo n.º 2
0
void VC::RemoveTask(const TaskPtr& task) {
    //里面有并发控制机制
    TaskState ts = task->GetTaskState();
    assert(ts == TASK_WAIT || ts == TASK_RUN);
    if(ts == TASK_WAIT) {
        m_wait_queue.Erase(task->GetId());    
    } else {
        m_run_queue.Erase(task->GetId());
    }
}
Ejemplo n.º 3
0
//这个错误处理是很麻烦的事情
void VC::KillTask(const TaskPtr& task) {
    TaskState ts = task->GetTaskState();
    assert(ts == TASK_WAIT || ts == TASK_RUN);
    if(ts == TASK_WAIT) {
        m_wait_queue.Erase(task->GetId());
    } else {  
        try {
            string endpoint = task->GetRunOn();
            Proxy<WorkerClient> proxy = Rpc<WorkerClient, WorkerClient>::GetProxy(endpoint);
            if(proxy().KillTask(task->GetId()) != 0) {
                 LOG4CPLUS_ERROR(logger, "delete task " << task->GetId() << " failed");
                 return;
            }
            m_run_queue.Erase(task->GetId());
        }  catch (TException &tx) {
            LOG4CPLUS_ERROR(logger, "delte task error " << task->GetId() << " failed");
        }
    }
}
Ejemplo n.º 4
0
// add m_used_cpu and m_used_memory of group
bool GroupPool::AddUsedResource(const TaskPtr& task_ptr) {
    if (task_ptr->GetTaskState() != TASK_WAITING) {
        // restart
        return true;    
    }

    GroupPtr group_ptr = GetGroupPtr(task_ptr->GetGroupName());
    if (!group_ptr) {
        LOG4CPLUS_ERROR(logger, "No this group, group name: " << task_ptr->GetGroupName());
        return false;
    }

    double factor = 1.0;
    int32_t priority = task_ptr->GetRawPriority();
    if (JOB_RAW_PRIO_PRIVILEGE == priority) {
        factor = m_privilege_factor;
    }
    
    group_ptr->SetUsedCPU(task_ptr->GetNeedCpu() * factor);
    group_ptr->SetUsedMemory(task_ptr->GetNeedMemory() * factor);
    return true;
}