@@ -9,6 +9,7 @@ import 'dart:io';
99import 'package:clock/clock.dart' ;
1010import 'package:gcloud/service_scope.dart' as ss;
1111import 'package:googleapis/compute/v1.dart' hide Duration;
12+ import 'package:googleapis/compute/v1.dart' as compute_v1 show Duration;
1213import 'package:http/http.dart' as http;
1314import 'package:logging/logging.dart' show Logger;
1415import 'package:meta/meta.dart' ;
@@ -456,13 +457,15 @@ runcmd:
456457 name: instanceName,
457458 description: description,
458459 machineType: 'zones/$zone /machineTypes/$_machineType ' ,
459- scheduling: _Scheduling (
460+ scheduling: Scheduling (
460461 preemptible: true ,
461462 automaticRestart: false ,
462463 onHostMaintenance: 'TERMINATE' ,
463464 instanceTerminationAction: 'DELETE' ,
464465 provisioningModel: 'SPOT' ,
465- maxRunDuration: _maxRunDuration,
466+ maxRunDuration: compute_v1.Duration (
467+ seconds: _maxRunDuration.inSeconds.toString (),
468+ ),
466469 ),
467470 labels: {
468471 // Labels that allows us to filter instances when listing instances.
@@ -774,49 +777,3 @@ DateTime _parseInstanceCreationTimestamp(String? timestamp) {
774777 return DateTime (0 );
775778 }
776779}
777-
778- /// Extend [Scheduling] with support for [maxRunDuration] .
779- ///
780- /// This is only available in the Compute Beta API, but extremely useful for
781- /// our use case, because GCE will then automatically delete instances.
782- ///
783- /// The [maxRunDuration] property is encoded as:
784- /// ```
785- /// "maxRunDuration": {
786- /// "seconds": string,
787- /// "nanos": integer
788- /// },
789- /// ```
790- /// For details, see reference documentation:
791- /// https://cloud.google.com/compute/docs/reference/rest/beta/instances/insert
792- class _Scheduling extends Scheduling {
793- /// Specifies the max run duration for the given instance.
794- ///
795- /// If specified, the instance termination action will be performed at the
796- /// end of the run duration.
797- Duration ? maxRunDuration;
798-
799- _Scheduling ({
800- super .automaticRestart,
801- super .instanceTerminationAction,
802- super .locationHint, // ignore: unused_element
803- super .minNodeCpus, // ignore: unused_element
804- super .nodeAffinities, // ignore: unused_element
805- super .onHostMaintenance,
806- super .preemptible,
807- super .provisioningModel,
808- this .maxRunDuration,
809- });
810-
811- @override
812- Map <String , dynamic > toJson () {
813- final maxRunDuration_ = maxRunDuration;
814- return < String , dynamic > {
815- ...super .toJson (),
816- if (maxRunDuration_ != null )
817- 'maxRunDuration' : < String , dynamic > {
818- 'seconds' : '${maxRunDuration_ .inSeconds }' ,
819- },
820- };
821- }
822- }
0 commit comments