Skip to content

Commit

Permalink
feat: add a warning about starving ships
Browse files Browse the repository at this point in the history
  • Loading branch information
eseidel committed Sep 30, 2023
1 parent 222790e commit 5ee3eb2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/cli/lib/logic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ Future<void> advanceShips(
waiter.scheduleShip(shipSymbol, expiration);
}
}

// Print a warning about any ships that have been waiting too long.
final oneMinuteAgo =
DateTime.timestamp().subtract(const Duration(minutes: 1));
final starvedShips = waiter.starvedShips(oneMinuteAgo);
if (starvedShips.isNotEmpty) {
logger.warn('⚠️ ${starvedShips.length} starved ships: $starvedShips');
}
}

/// RateLimitTracker tracks the rate limit usage and prints stats.
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/lib/ship_waiter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ class ShipWaiter {

/// Returns the next ship to be processed.
ShipWaiterEntry nextShip() => _queue.removeFirst();

/// Returns a list of ShipSymbols that have been waiting too long.
Iterable<ShipSymbol> starvedShips(DateTime starvationThreshold) sync* {
for (final entry in _queue.toUnorderedList()) {
if (entry.waitUntil != null &&
entry.waitUntil!.isBefore(starvationThreshold)) {
yield entry.shipSymbol;
}
}
}
}

0 comments on commit 5ee3eb2

Please sign in to comment.