class_docstr: A handler for check-ins for a given run.
  
  Uses filesystem to store the check-ins. Handles resumed `Run`s.
  Background thread is used to adjust the rate of check-ins written
  to the filesystem in order to avoid overloading.
  
  Calling `report_successful_finish()` is required to mark the run as
  finished, otherwise the run will be marked as failed.
class_docstr_tok: ["A","handler","for","check-ins","for","a","given","run",".","Uses","filesystem","to","store","the","check-ins",".","Handles","resumed","`","Run","`","s",".","Background","thread","is","used","to","adjust","the","rate","of","check-ins","written","to","the","filesystem","in","order","to","avoid","overloading",".","Calling","`","report_successful_finish","(",")","`","is","required","to","mark","the","run","as","finished",",","otherwise","the","run","will","be","marked","as","failed","."]
docstr: The writer thread that periodically flushes the last check-in.
  This background thread also takes care of cleaning up expired check-ins
  and throttling the check-in rate in order to avoid overloading the
  filesystem. However, it can be notified to flush the last check-in
  on-demand. This is useful when reporting certain events that are preferable
  to be reported as soon as possible, e.g. success status of the Run.
code: def _writer(self):
      """
      The writer thread that periodically flushes the last check-in.
      This background thread also takes care of cleaning up expired check-ins
      and throttling the check-in rate in order to avoid overloading the
      filesystem. However, it can be notified to flush the last check-in
      on-demand. This is useful when reporting certain events that are preferable
      to be reported as soon as possible, e.g. success status of the Run.
      """
  
      remaining = 0
      while True:
          # First we need to decide how much time we need to wait to reach the
          # next appropriate flush time. It is either the remaining time from
          # the previous flush, or the moment new check-in is registered.
          with self.refresh_condition:
              logger.debug(
                  f"no interesting things to do, sleeping for {remaining}"
              )
              logger.debug("until woken up")
              logger.debug(
                  f"unfinished tasks: {self.queue.unfinished_tasks}"
              )
              self.refresh_condition.wait(timeout=remaining)
  
          timed_task: Optional[TimedTask]
          try:
              timed_task = self.queue.get(timeout=0)
          except queue.Empty:
              timed_task = None
          else:
              assert isinstance(timed_task, TimedTask)
  
              if timed_task.overwritten:
                  logger.debug("detected overwritten task... done")
                  self.queue.task_done()
                  continue
  
              remaining = (
                  timed_task.when - time.monotonic() - PLAN_ADVANCE_TIME
              )
              # remaining = max(remaining, MIN_SUSPEND_TIME)
              remaining = min(remaining, MAX_SUSPEND_TIME)
              logger.debug(f"time remaining: {remaining}")
  
              if remaining > 0:
                  # TODO Should we push a little late?
                  self._schedule(timed_task)
                  logger.debug(f"too soon, {remaining} remaining")
                  logger.debug(
                      f"putting back for the future: {timed_task}"
                  )
                  logger.debug(
                      f"now: {time.monotonic()}... scheduled for: {timed_task.when}"
                  )
                  self.queue.task_done()
                  # Mark the task to signal about the clean state.
                  timed_task = None
  
          # If during the last iteration we could not find a new check-in
          # to flush, we define it as clean state. In the case of if the stop
          # signal is set, we can safely exit the thread as there will be no
          # more check-ins to process in the future.
          if timed_task is None:
              remaining = MAX_SUSPEND_TIME
              with self.flush_condition:
                  self.flush_condition.notify()
              if self.stop_signal.is_set():
                  return
          else:
              logger.debug(
                  f"only {remaining} remaining... flushing one task"
              )
              self._touch_flag(timed_task.flag_name)
              self.queue.task_done()
              # Let's immediately proceed to the next iteration to check if
              # there are any new check-ins to flush.
              remaining = IMMEDIATELY
  
imports: import math
  import time
  import queue
  import threading
  from collections import defaultdict
  from dataclasses import dataclass, field
  from pathlib import Path
  from typing import ClassVar, Dict, Optional, Tuple, Set, Union, TYPE_CHECKING
  from cachetools import LRUCache
  from aim.sdk.reporter.file_manager import FileManager
  import logging
label_desc: Use image node_id 8 for calling the RunStatusReporter obj's underlying member method code with example usage: obj._writer() without return types