step 4
This commit is contained in:
@@ -21,17 +21,29 @@ struct PersistenceWriterMetrics
|
||||
uint64_t failedCount = 0;
|
||||
};
|
||||
|
||||
struct PersistenceWriteResult
|
||||
{
|
||||
PersistenceTargetKind targetKind = PersistenceTargetKind::RuntimeState;
|
||||
std::string targetPath;
|
||||
std::string reason;
|
||||
bool succeeded = false;
|
||||
std::string errorMessage;
|
||||
bool newerRequestPending = false;
|
||||
};
|
||||
|
||||
class PersistenceWriter
|
||||
{
|
||||
public:
|
||||
using SnapshotSink = std::function<bool(const PersistenceSnapshot&, std::string&)>;
|
||||
using ResultCallback = std::function<void(const PersistenceWriteResult&)>;
|
||||
|
||||
explicit PersistenceWriter(
|
||||
std::chrono::milliseconds debounceDelay = std::chrono::milliseconds(50),
|
||||
SnapshotSink sink = SnapshotSink());
|
||||
~PersistenceWriter();
|
||||
|
||||
bool WriteSnapshot(const PersistenceSnapshot& snapshot, std::string& error) const;
|
||||
void SetResultCallback(ResultCallback callback);
|
||||
bool WriteSnapshot(const PersistenceSnapshot& snapshot, std::string& error);
|
||||
bool EnqueueSnapshot(const PersistenceSnapshot& snapshot, std::string& error);
|
||||
void StopAndFlush();
|
||||
PersistenceWriterMetrics GetMetrics() const;
|
||||
@@ -45,12 +57,14 @@ private:
|
||||
|
||||
bool ValidateSnapshot(const PersistenceSnapshot& snapshot, std::string& error) const;
|
||||
bool WriteSnapshotThroughSink(const PersistenceSnapshot& snapshot, std::string& error) const;
|
||||
void PublishWriteResult(const PersistenceSnapshot& snapshot, bool succeeded, const std::string& errorMessage, bool newerRequestPending);
|
||||
void StartWorkerLocked();
|
||||
void WorkerMain();
|
||||
std::size_t PendingCountLocked() const;
|
||||
|
||||
std::chrono::milliseconds mDebounceDelay;
|
||||
SnapshotSink mSink;
|
||||
ResultCallback mResultCallback;
|
||||
mutable std::mutex mMutex;
|
||||
std::condition_variable mCondition;
|
||||
std::thread mWorker;
|
||||
|
||||
Reference in New Issue
Block a user