void PrePostProcessor::Stop() { Thread::Stop(); DownloadQueue* pDownloadQueue = g_pQueueCoordinator->LockQueue(); #ifndef DISABLE_PARCHECK m_ParCoordinator.Stop(); #endif if (!pDownloadQueue->GetPostQueue()->empty()) { PostInfo* pPostInfo = pDownloadQueue->GetPostQueue()->front(); if ((pPostInfo->GetStage() == PostInfo::ptUnpacking || pPostInfo->GetStage() == PostInfo::ptExecutingScript) && pPostInfo->GetPostThread()) { Thread* pPostThread = pPostInfo->GetPostThread(); pPostInfo->SetPostThread(NULL); pPostThread->SetAutoDestroy(true); pPostThread->Stop(); } } g_pQueueCoordinator->UnlockQueue(); }
bool PrePostProcessor::PostQueueDelete(DownloadQueue* downloadQueue, IdList* idList) { bool ok = false; for (int id : *idList) { for (NzbInfo* nzbInfo: downloadQueue->GetQueue()) { PostInfo* postInfo = nzbInfo->GetPostInfo(); if (postInfo && nzbInfo->GetId() == id) { if (postInfo->GetWorking()) { postInfo->GetNzbInfo()->PrintMessage(Message::mkInfo, "Deleting active post-job %s", postInfo->GetNzbInfo()->GetName()); postInfo->SetDeleted(true); if (postInfo->GetPostThread()) { debug("Terminating post-process thread for %s", postInfo->GetNzbInfo()->GetName()); postInfo->GetPostThread()->Stop(); ok = true; } else if (postInfo->GetNzbInfo()->GetUnpackThread()) { ((DirectUnpack*)postInfo->GetNzbInfo()->GetUnpackThread())->NzbDeleted(downloadQueue, postInfo->GetNzbInfo()); ok = true; } else { error("Internal error in PrePostProcessor::QueueDelete"); } } else { postInfo->GetNzbInfo()->PrintMessage(Message::mkInfo, "Deleting queued post-job %s", postInfo->GetNzbInfo()->GetName()); JobCompleted(downloadQueue, postInfo); m_activeJobs.erase(std::remove_if(m_activeJobs.begin(), m_activeJobs.end(), [postInfo](NzbInfo* postJob) { return postInfo == postJob->GetPostInfo(); }), m_activeJobs.end()); ok = true; } break; } } } if (ok) { downloadQueue->Save(); } return ok; }
bool PrePostProcessor::PostQueueDelete(IDList* pIDList) { bool bOK = false; DownloadQueue* pDownloadQueue = g_pQueueCoordinator->LockQueue(); for (IDList::iterator itID = pIDList->begin(); itID != pIDList->end(); itID++) { int iID = *itID; for (PostQueue::iterator itPost = pDownloadQueue->GetPostQueue()->begin(); itPost != pDownloadQueue->GetPostQueue()->end(); itPost++) { PostInfo* pPostInfo = *itPost; if (pPostInfo->GetID() == iID) { if (pPostInfo->GetWorking()) { info("Deleting active post-job %s", pPostInfo->GetInfoName()); pPostInfo->SetDeleted(true); #ifndef DISABLE_PARCHECK if (PostInfo::ptLoadingPars <= pPostInfo->GetStage() && pPostInfo->GetStage() <= PostInfo::ptRenaming) { if (m_ParCoordinator.Cancel()) { bOK = true; } } else #endif if (pPostInfo->GetPostThread()) { debug("Terminating %s for %s", (pPostInfo->GetStage() == PostInfo::ptUnpacking ? "unpack" : "post-process-script"), pPostInfo->GetInfoName()); pPostInfo->GetPostThread()->Stop(); bOK = true; } else { error("Internal error in PrePostProcessor::QueueDelete"); } } else { info("Deleting queued post-job %s", pPostInfo->GetInfoName()); JobCompleted(pDownloadQueue, pPostInfo); bOK = true; } break; } } } g_pQueueCoordinator->UnlockQueue(); return bOK; }
bool PrePostProcessor::PostQueueDelete(DownloadQueue* downloadQueue, IdList* idList) { bool ok = false; for (int id : *idList) { for (NzbInfo* nzbInfo: downloadQueue->GetQueue()) { PostInfo* postInfo = nzbInfo->GetPostInfo(); if (postInfo && nzbInfo->GetId() == id) { if (postInfo->GetWorking()) { postInfo->GetNzbInfo()->PrintMessage(Message::mkInfo, "Deleting active post-job %s", postInfo->GetNzbInfo()->GetName()); postInfo->SetDeleted(true); #ifndef DISABLE_PARCHECK if (PostInfo::ptLoadingPars <= postInfo->GetStage() && postInfo->GetStage() <= PostInfo::ptRenaming) { if (m_parCoordinator.Cancel()) { ok = true; } } else #endif if (postInfo->GetPostThread()) { debug("Terminating %s for %s", (postInfo->GetStage() == PostInfo::ptUnpacking ? "unpack" : "post-process-script"), postInfo->GetNzbInfo()->GetName()); postInfo->GetPostThread()->Stop(); ok = true; } else { error("Internal error in PrePostProcessor::QueueDelete"); } } else { postInfo->GetNzbInfo()->PrintMessage(Message::mkInfo, "Deleting queued post-job %s", postInfo->GetNzbInfo()->GetName()); JobCompleted(downloadQueue, postInfo); ok = true; } break; } } } return ok; }
void PrePostProcessor::CleanupJobs(DownloadQueue* downloadQueue) { m_activeJobs.erase(std::remove_if(m_activeJobs.begin(), m_activeJobs.end(), [processor = this, downloadQueue](NzbInfo* postJob) { PostInfo* postInfo = postJob->GetPostInfo(); if (!postInfo->GetWorking() && !(postInfo->GetPostThread() && postInfo->GetPostThread()->IsRunning())) { delete postInfo->GetPostThread(); postInfo->SetPostThread(nullptr); postInfo->SetStageTime(0); postInfo->SetStageProgress(0); postInfo->SetFileProgress(0); postInfo->SetProgressLabel(""); if (postInfo->GetStartTime() > 0) { postJob->SetPostTotalSec(postJob->GetPostTotalSec() + (int)(Util::CurrentTime() - postInfo->GetStartTime())); postInfo->SetStartTime(0); } if (postInfo->GetStage() == PostInfo::ptFinished || postInfo->GetDeleted()) { processor->JobCompleted(downloadQueue, postInfo); } else { postInfo->SetStage(PostInfo::ptQueued); } return true; } return false; }), m_activeJobs.end()); }