JobPtr Peer::GetJob(int peerId, int taskId, PeerNodePtr pNode) { std::map<int, JobPtr>::iterator it; for(it = m_jobList.begin(); it != m_jobList.end(); it++) { JobPtr pJob = (*it).second; if(pJob->GetTaskId() == taskId && pJob->GetRemotePeerId() == peerId) if(pNode == NULL) return pJob; else if(pNode == pJob->GetPeerNode()) return pJob; } return JobPtr(); }
void Peer::HandleJobExecution(WMessagePtr pMsg) { bool bJobResult = false; SYS_MSG sysMsg = pMsg->GetSysMsg(); if(sysMsg == TASK_EXECUTION_SUCCESS) { bJobResult = true; int jobId = pMsg->GetJobId(); if(jobId <= 0) { Log(ERR, L"Peer::HandleJobExecution Message from Invalid Job.. Ignoring it\n"); return; } // find the job if(m_jobList.find(jobId) == m_jobList.end()) { Log(ERR, L"Peer::HandleJobExecution Message from Invalid Job.. Ignoring it\n"); return; } JobPtr pJob = m_jobList[jobId]; // send the response to remote peer RemotePeers rpeer = this->GetRemotePeerById(pJob->GetRemotePeerId()); // get the stats and put in workhistory double execTime = pJob->GetExecutionTime(); WorkHistoryPtr pWH = WorkHistory::GetWorkHistory(); pWH->SetNewFinishTaskInfo(execTime, true); // not found in db // [TODO] handle when peer not found in db if(rpeer.peer_id < 0) { Log(ERR, L"Peer::HandleJobExecution Peer: %d, Not found in DB for job: %d, still sending the result\n", pJob->GetRemotePeerId(), jobId); } //PeerNodePtr pNode = PeerNode::CreatePeerNode(rpeer); PeerNodePtr pNode = pJob->GetPeerNode(); pNode->TaskExecuteResult(pJob->GetTaskId(), bJobResult, pJob->GetResult(), pJob->GetParam()); } }