restartLoopDetected static method

bool restartLoopDetected({
  1. required Duration within,
  2. required int more,
})

More than more restarts inside within: the loop the spec names.

Implementation

static bool restartLoopDetected({required Duration within, required int more}) {
  if (!_restarts.existsSync()) return false;
  final DateTime since = DateTime.now().toUtc().subtract(within);
  int recent = 0;
  for (final String line in _restarts.readAsLinesSync()) {
    final DateTime? at = DateTime.tryParse(line.trim());
    if (at != null && at.isAfter(since)) recent++;
  }
  return recent > more;
}