changeset 4341:977c2759eb0a

Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 03 Dec 2020 18:15:47 +0100
parents 6fa8bb987be2
children 52166629239f
files NEWS OrthancServer/Sources/ServerJobs/ArchiveJob.cpp OrthancServer/Sources/ServerJobs/ArchiveJob.h
diffstat 3 files changed, 26 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Thu Dec 03 15:58:52 2020 +0100
+++ b/NEWS	Thu Dec 03 18:15:47 2020 +0100
@@ -19,6 +19,7 @@
 * "/modalities/{id}/configuration": Get the configuration of one modality (cf. "/modalities?expand")
 * "/tools/dicom-echo" and "/modalities/{id}/echo" now accept the field "CheckFind" in their JSON
   body to complement C-GET SCU with C-FIND SCU ("DicomEchoChecksFind" on a per-connection basis)
+* Archive/media jobs report the size of the created ZIP file in content field "ArchiveSizeMB"
 
 Maintenance
 -----------
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Thu Dec 03 15:58:52 2020 +0100
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.cpp	Thu Dec 03 18:15:47 2020 +0100
@@ -56,6 +56,7 @@
 static const char* const KEY_DESCRIPTION = "Description";
 static const char* const KEY_INSTANCES_COUNT = "InstancesCount";
 static const char* const KEY_UNCOMPRESSED_SIZE_MB = "UncompressedSizeMB";
+static const char* const KEY_ARCHIVE_SIZE_MB = "ArchiveSizeMB";
 static const char* const KEY_TRANSCODE = "Transcode";
 
 
@@ -851,6 +852,7 @@
     currentStep_(0),
     instancesCount_(0),
     uncompressedSize_(0),
+    archiveSize_(0),
     transcode_(false),
     transferSyntax_(DicomTransferSyntax_LittleEndianImplicit)
   {
@@ -993,10 +995,26 @@
   }
   
 
+  void ArchiveJob::RefreshArchiveSize()
+  {
+    if (synchronousTarget_.get() != NULL)
+    {
+      archiveSize_ = synchronousTarget_->GetFileSize();
+    }
+        
+    if (asynchronousTarget_.get() != NULL)
+    {
+      archiveSize_ = asynchronousTarget_->GetFileSize();
+    }
+  }
+    
+
   void ArchiveJob::FinalizeTarget()
   {
     writer_.reset();  // Flush all the results
 
+    RefreshArchiveSize();
+    
     if (asynchronousTarget_.get() != NULL)
     {
       // Asynchronous behavior: Move the resulting file into the media archive
@@ -1017,7 +1035,7 @@
       return JobStepResult::Failure(ErrorCode_NetworkProtocol,
                                     "A client has disconnected while creating an archive");
     }
-        
+
     if (writer_->GetStepsCount() == 0)
     {
       FinalizeTarget();
@@ -1036,6 +1054,7 @@
       }
       else
       {
+        RefreshArchiveSize();
         return JobStepResult::Continue();
       }
     }
@@ -1077,6 +1096,8 @@
     value[KEY_INSTANCES_COUNT] = instancesCount_;
     value[KEY_UNCOMPRESSED_SIZE_MB] =
       static_cast<unsigned int>(uncompressedSize_ / MEGA_BYTES);
+    value[KEY_ARCHIVE_SIZE_MB] =
+      static_cast<unsigned int>(archiveSize_ / MEGA_BYTES);
 
     if (transcode_)
     {
--- a/OrthancServer/Sources/ServerJobs/ArchiveJob.h	Thu Dec 03 15:58:52 2020 +0100
+++ b/OrthancServer/Sources/ServerJobs/ArchiveJob.h	Thu Dec 03 18:15:47 2020 +0100
@@ -67,11 +67,14 @@
     size_t                                currentStep_;
     unsigned int                          instancesCount_;
     uint64_t                              uncompressedSize_;
+    uint64_t                              archiveSize_;
     std::string                           mediaArchiveId_;
 
     // New in Orthanc 1.7.0
     bool                 transcode_;
     DicomTransferSyntax  transferSyntax_;
+
+    void RefreshArchiveSize();
     
     void FinalizeTarget();