# HG changeset patch # User Sebastien Jodogne # Date 1544029331 -3600 # Node ID 2c16c29b287d43ba00f35668e8b42cf5e005b82f # Parent e361df74639fa817b826983bd7947d694eda93c5 preparing for asynchronous generation of archives diff -r e361df74639f -r 2c16c29b287d OrthancServer/OrthancRestApi/OrthancRestArchive.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestArchive.cpp Wed Dec 05 16:30:28 2018 +0100 +++ b/OrthancServer/OrthancRestApi/OrthancRestArchive.cpp Wed Dec 05 18:02:11 2018 +0100 @@ -114,9 +114,10 @@ } - static void SubmitJob(RestApiCall& call, + static void SubmitJob(RestApiOutput& output, ServerContext& context, std::auto_ptr& job, + bool synchronous, const std::string& filename) { if (job.get() == NULL) @@ -126,25 +127,32 @@ job->SetDescription("REST API"); - boost::shared_ptr tmp(new TemporaryFile); - job->SetSynchronousTarget(tmp); - - Json::Value publicContent; - if (context.GetJobsEngine().GetRegistry().SubmitAndWait - (publicContent, job.release(), 0 /* TODO priority */)) + if (synchronous) { - // The archive is now created: Prepare the sending of the ZIP file - FilesystemHttpSender sender(tmp->GetPath()); - sender.SetContentType(MimeType_Gzip); - sender.SetContentFilename(filename); + boost::shared_ptr tmp(new TemporaryFile); + job->SetSynchronousTarget(tmp); + + Json::Value publicContent; + if (context.GetJobsEngine().GetRegistry().SubmitAndWait + (publicContent, job.release(), 0 /* TODO priority */)) + { + // The archive is now created: Prepare the sending of the ZIP file + FilesystemHttpSender sender(tmp->GetPath()); + sender.SetContentType(MimeType_Gzip); + sender.SetContentFilename(filename); - // Send the ZIP - call.GetOutput().AnswerStream(sender); + // Send the ZIP + output.AnswerStream(sender); + } + else + { + output.SignalError(HttpStatus_500_InternalServerError); + } } else { - call.GetOutput().SignalError(HttpStatus_500_InternalServerError); - } + throw OrthancException(ErrorCode_NotImplemented); + } } @@ -160,7 +168,7 @@ std::auto_ptr job(new ArchiveJob(context, false, extended)); AddResourcesOfInterest(*job, body); - SubmitJob(call, context, job, "Archive.zip"); + SubmitJob(call.GetOutput(), context, job, synchronous, "Archive.zip"); } else { @@ -183,7 +191,7 @@ std::auto_ptr job(new ArchiveJob(context, true, extended)); AddResourcesOfInterest(*job, body); - SubmitJob(call, context, job, "Archive.zip"); + SubmitJob(call.GetOutput(), context, job, synchronous, "Archive.zip"); } else { @@ -202,7 +210,7 @@ std::auto_ptr job(new ArchiveJob(context, false, false)); job->AddResource(id); - SubmitJob(call, context, job, id + ".zip"); + SubmitJob(call.GetOutput(), context, job, true /* synchronous */, id + ".zip"); } @@ -215,7 +223,7 @@ std::auto_ptr job(new ArchiveJob(context, true, call.HasArgument("extended"))); job->AddResource(id); - SubmitJob(call, context, job, id + ".zip"); + SubmitJob(call.GetOutput(), context, job, true /* synchronous */, id + ".zip"); }