def _is_time_to_call_stats_func_and_update_ts()

in postgresql_metrics/metrics_logic.py [0:0]


def _is_time_to_call_stats_func_and_update_ts(database_name, metrics_func, run_interval_sec):
    """Check if it is time to schedule new metrics gathering call,
    and assume the call will be made immediately if yes.
    This means that the call timestamp for the given database_name and metrics_func
    is updated within this function.
    """
    last_run_timestamp = LAST_RUN_TIMES_FOR_STATS.get(database_name, {}).get(metrics_func, 0)
    if time.time() - last_run_timestamp > run_interval_sec:
        if database_name not in LAST_RUN_TIMES_FOR_STATS:
            LAST_RUN_TIMES_FOR_STATS[database_name] = {}
        LAST_RUN_TIMES_FOR_STATS[database_name][metrics_func] = time.time()
        return True
    return False