StatusFile

class StatusFile

Rate-limited JSON status file, merged from possibly multiple sources.

Lets several parts of a run (or several processes) report progress into the same file without flooding the disk: write merges its argument into the accumulated content and only actually rewrites the file at most every min_interval_sec, unless forced.

Public Functions

explicit StatusFile(const std::string &file_name, double min_interval_sec = 10.0)
Parameters:
  • file_name – Path the status is written to.

  • min_interval_sec – Minimum time between two file rewrites.

void write(const nlohmann::json &content, bool force_write = false)

Merge content into the accumulated status.

Top-level keys of content overwrite the corresponding accumulated ones; the "run_times" key is merged one level deeper instead. The file is rewritten if force_write is set, if this is the first call, or if min_interval_sec has passed since the last rewrite.

~StatusFile()

If a status was written and its "status" field is not "done", sets it to "done" and writes the file out one last time.