diff --git a/packages/cli/lib/logic.dart b/packages/cli/lib/logic.dart index 983ab869..e7cd42de 100644 --- a/packages/cli/lib/logic.dart +++ b/packages/cli/lib/logic.dart @@ -89,6 +89,14 @@ Future 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. diff --git a/packages/cli/lib/ship_waiter.dart b/packages/cli/lib/ship_waiter.dart index 54b0b7e7..f08c8b12 100644 --- a/packages/cli/lib/ship_waiter.dart +++ b/packages/cli/lib/ship_waiter.dart @@ -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 starvedShips(DateTime starvationThreshold) sync* { + for (final entry in _queue.toUnorderedList()) { + if (entry.waitUntil != null && + entry.waitUntil!.isBefore(starvationThreshold)) { + yield entry.shipSymbol; + } + } + } }