@@ -3,6 +3,7 @@ import 'dart:convert';
33import 'dart:math' ;
44
55import 'package:_pub_shared/data/task_payload.dart' ;
6+ import 'package:basics/basics.dart' ;
67import 'package:clock/clock.dart' ;
78import 'package:logging/logging.dart' show Logger;
89import 'package:meta/meta.dart' ;
@@ -36,18 +37,14 @@ Future<(CreateInstancesState, Duration)> runOneCreateInstancesCycle(
3637}) async {
3738 // Map from zone to DateTime when zone is allowed again
3839 final zoneBannedUntil = < String , DateTime > {
39- for (final zone in compute.zones) zone: DateTime (0 ),
40- ...state.zoneBannedUntil,
40+ ...state.zoneBannedUntil.whereValue ((v) => v.isAfter (clock.now ())),
4141 };
4242 void banZone (String zone, {int minutes = 0 , int hours = 0 , int days = 0 }) {
43- if (! zoneBannedUntil.containsKey (zone)) {
44- throw ArgumentError .value (zone, 'zone' );
45- }
46-
4743 final until = clock.now ().add (
4844 Duration (minutes: minutes, hours: hours, days: days),
4945 );
50- if (zoneBannedUntil[zone]! .isBefore (until)) {
46+ if (! zoneBannedUntil.containsKey (zone) ||
47+ zoneBannedUntil[zone]! .isBefore (until)) {
5148 zoneBannedUntil[zone] = until;
5249 }
5350 }
@@ -72,9 +69,11 @@ Future<(CreateInstancesState, Duration)> runOneCreateInstancesCycle(
7269
7370 // Determine which zones are not banned
7471 final allowedZones =
75- zoneBannedUntil.entries
76- .where ((e) => e.value.isBefore (clock.now ()))
77- .map ((e) => e.key)
72+ compute.zones
73+ .where (
74+ (zone) =>
75+ (zoneBannedUntil[zone] ?? DateTime (0 )).isBefore (clock.now ()),
76+ )
7877 .toList ()
7978 ..shuffle (rng);
8079 var nextZoneIndex = 0 ;
0 commit comments