diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-04-10 20:22:35 +0100 |
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-04-10 20:22:35 +0100 |
| commit | 72bfa9dd305258789b0d2e80f8af13962e5aac42 (patch) | |
| tree | 4f4dd17921154452289107fae6b6358047f35bce /src | |
| parent | 1e551e618a63c869fde6a4b327566b38696a5f45 (diff) | |
| download | webstat-72bfa9dd305258789b0d2e80f8af13962e5aac42.tar.bz2 webstat-72bfa9dd305258789b0d2e80f8af13962e5aac42.tar.xz webstat-72bfa9dd305258789b0d2e80f8af13962e5aac42.zip | |
Return path of parked lines log file from parkQueuedLogLines
Or the last errno on failure.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ingestor.cpp | 13 | ||||
| -rw-r--r-- | src/ingestor.hpp | 3 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/ingestor.cpp b/src/ingestor.cpp index c5cb8d8..0659f1f 100644 --- a/src/ingestor.cpp +++ b/src/ingestor.cpp @@ -275,11 +275,11 @@ namespace WebStat { } } - void + std::expected<std::filesystem::path, int> Ingestor::parkQueuedLogLines() { if (queuedLines.empty()) { - return; + return std::unexpected(0); } const std::filesystem::path path { settings.fallbackDir / std::format("parked-{}.short", crc32(queuedLines.front()))}; @@ -290,16 +290,19 @@ namespace WebStat { } if (fflush(parked.get()) == 0) { queuedLines.clear(); - auto finalPath = auto {path}.replace_extension(".log"); + auto finalPath = std::filesystem::path {path}.replace_extension(".log"); + parked.reset(); if (rename(path.c_str(), finalPath.c_str()) == 0) { - return; + return finalPath; } } } + const int err = errno; log(LOG_ERR, "Failed to park %zu queued lines:", queuedLines.size()); for (const auto & line : queuedLines) { log(LOG_ERR, "\t%.*s", static_cast<int>(line.length()), line.data()); } + return std::unexpected(err); } void @@ -334,7 +337,7 @@ namespace WebStat { unsigned int count = 0; for (auto pathIter = std::filesystem::directory_iterator {settings.fallbackDir}; pathIter != std::filesystem::directory_iterator {}; ++pathIter) { - if (scn::scan<Crc32Value>(pathIter->path().filename().string(), "parked-{}.log")) { + if (scn::scan<std::string>(pathIter->path().filename().string(), "parked-{:[a-zA-Z0-9]}.log")) { jobIngestParkedLines(pathIter->path()); count += 1; } diff --git a/src/ingestor.hpp b/src/ingestor.hpp index fcddc92..b2e0fed 100644 --- a/src/ingestor.hpp +++ b/src/ingestor.hpp @@ -7,6 +7,7 @@ #include <connectionPool.h> #include <connection_fwd.h> #include <cstdio> +#include <expected> #include <flat_set> #include <future> #include <scn/scan.h> @@ -54,7 +55,7 @@ namespace WebStat { void ingestLog(std::FILE *); void tryIngestQueuedLogLines(); void ingestLogLines(DB::Connection *, const LineBatch & lines); - void parkQueuedLogLines(); + std::expected<std::filesystem::path, int> parkQueuedLogLines(); void runJobsAsNeeded(); unsigned int jobIngestParkedLines(); |
