diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-08-24 15:17:58 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-08-24 15:17:58 +0200 |
commit | 35ff21c72e65d1e01678d67c7dd985e2959d4ebf (patch) | |
tree | ea38cb2099a1bdac8e61359ea6d503642787be1d /bbot/worker/worker.cxx | |
parent | 677c50eebf74b3b0d09f46e8be89506a9025f8ba (diff) |
Truncate operation result logs if too large
Diffstat (limited to 'bbot/worker/worker.cxx')
-rw-r--r-- | bbot/worker/worker.cxx | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/bbot/worker/worker.cxx b/bbot/worker/worker.cxx index d7a2570..1f5c946 100644 --- a/bbot/worker/worker.cxx +++ b/bbot/worker/worker.cxx @@ -2070,6 +2070,46 @@ build (size_t argc, const char* argv[]) rm.status |= r.status; } + + // Truncate logs if they would exceed the upload limit. + // + // @@ TMP: currently this limit is hard-coded. In the future it should be + // sent along with the task manifest. + // + const size_t upload_limit (10 * 1024 * 1024); + { + // Reserve 10K for other manifest values (alternatively, we could do it + // exactly in upload_manifest()). + // + const size_t manifest_size (10 * 1024); + + size_t n (manifest_size); + for (const operation_result& r: rm.results) + n += r.log.size (); + + if (n > upload_limit) + { + // Divide the size equally among all the operations and truncate any + // that exceed their allowance. This way we will get some information + // for each operation. + // + n = (upload_limit - manifest_size) / rm.results.size (); + + for (operation_result& r: rm.results) + { + if (r.log.size () <= n) + continue; + + // We need to be careful not to truncate it in the middle of UTF-8 + // sequence. So we look for the last newline that still fits. + // + size_t p (n - 80 /* for the "log truncated" note */); + for (; p != 0 && r.log[p] != '\n'; --p) ; + r.log.resize (p != 0 ? p + 1 : 0); // Keep the newline. + r.log += "-------------------------------LOG TRUNCATED-------------------------------\n"; + } + } + } } else assert (rm.status == result_status::abort); |