Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
#371: restart direct unpack after program reload
Browse files Browse the repository at this point in the history
When program is reloaded during direct unpack the unpack restarts after
one (any) inner file is downloaded.
  • Loading branch information
hugbug committed May 8, 2017
1 parent 66d1758 commit fe1d0ef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
4 changes: 1 addition & 3 deletions daemon/postprocess/DirectUnpack.cpp
Expand Up @@ -118,7 +118,7 @@ void DirectUnpack::Run()
GuardedDownloadQueue downloadQueue = DownloadQueue::Guard();

NzbInfo* nzbInfo = downloadQueue->GetQueue()->Find(m_nzbId);
if (!nzbInfo)
if (!nzbInfo || nzbInfo->GetUnpackThread() != this)
{
debug("Could not find NzbInfo for %s", *m_infoName);
return;
Expand All @@ -130,12 +130,10 @@ void DirectUnpack::Run()
if (nzbInfo->GetDirectUnpackStatus() == NzbInfo::nsSuccess && !GetTerminated())
{
nzbInfo->AddMessage(Message::mkInfo, BString<1024>("%s successful", *m_infoNameUp));

}
else if (nzbInfo->GetDirectUnpackStatus() == NzbInfo::nsFailure && !GetTerminated())
{
nzbInfo->AddMessage(Message::mkWarning, BString<1024>("%s failed", *m_infoNameUp));

}

AddExtraTime(nzbInfo);
Expand Down
32 changes: 30 additions & 2 deletions daemon/postprocess/PrePostProcessor.cpp
Expand Up @@ -77,7 +77,7 @@ void PrePostProcessor::WaitJobs()
{
debug("PrePostProcessor: waiting for jobs to complete");

// wait 5 seconds until all jobs gracefully finish
// wait 5 seconds until all post-processing jobs gracefully finish
time_t waitStart = Util::CurrentTime();
while (Util::CurrentTime() < waitStart + 5)
{
Expand All @@ -92,7 +92,7 @@ void PrePostProcessor::WaitJobs()
usleep(200 * 1000);
}

// kill remaining jobs; not safe but we can't wait any longer
// kill remaining post-processing jobs; not safe but we can't wait any longer
{
GuardedDownloadQueue downloadQueue = DownloadQueue::Guard();
for (NzbInfo* postJob : m_activeJobs)
Expand All @@ -108,6 +108,34 @@ void PrePostProcessor::WaitJobs()
}
}

// wait 5 seconds until direct unpack threads gracefully finish
waitStart = Util::CurrentTime();
while (Util::CurrentTime() < waitStart + 5)
{
{
GuardedDownloadQueue downloadQueue = DownloadQueue::Guard();
if (std::find_if(downloadQueue->GetQueue()->begin(),
downloadQueue->GetQueue()->end(),
[](const std::unique_ptr<NzbInfo>& nzbInfo)
{
return nzbInfo->GetUnpackThread() != nullptr;
}) == downloadQueue->GetQueue()->end())
{
break;
}
}
usleep(200 * 1000);
}

// disconnect remaining direct unpack jobs
{
GuardedDownloadQueue downloadQueue = DownloadQueue::Guard();
for (NzbInfo* nzbInfo : downloadQueue->GetQueue())
{
nzbInfo->SetUnpackThread(nullptr);
}
}

debug("PrePostProcessor: Jobs are completed");
}

Expand Down

0 comments on commit fe1d0ef

Please sign in to comment.