mirror of https://github.com/portainer/portainer
feat(service): change update delay format to a time string in service… (#1470)
parent
f3a23c7dd1
commit
728ef35cc1
|
@ -24,7 +24,7 @@ function ($q, $scope, $state, $timeout, Service, ServiceHelper, ConfigService, C
|
||||||
Parallelism: 1,
|
Parallelism: 1,
|
||||||
PlacementConstraints: [],
|
PlacementConstraints: [],
|
||||||
PlacementPreferences: [],
|
PlacementPreferences: [],
|
||||||
UpdateDelay: 0,
|
UpdateDelay: '0s',
|
||||||
UpdateOrder: 'stop-first',
|
UpdateOrder: 'stop-first',
|
||||||
FailureAction: 'pause',
|
FailureAction: 'pause',
|
||||||
Secrets: [],
|
Secrets: [],
|
||||||
|
@ -243,7 +243,7 @@ function ($q, $scope, $state, $timeout, Service, ServiceHelper, ConfigService, C
|
||||||
function prepareUpdateConfig(config, input) {
|
function prepareUpdateConfig(config, input) {
|
||||||
config.UpdateConfig = {
|
config.UpdateConfig = {
|
||||||
Parallelism: input.Parallelism || 0,
|
Parallelism: input.Parallelism || 0,
|
||||||
Delay: input.UpdateDelay * 1000000000 || 0,
|
Delay: ServiceHelper.translateHumanDurationToNanos(input.UpdateDelay),
|
||||||
FailureAction: input.FailureAction,
|
FailureAction: input.FailureAction,
|
||||||
Order: input.UpdateOrder
|
Order: input.UpdateOrder
|
||||||
};
|
};
|
||||||
|
|
|
@ -389,13 +389,16 @@
|
||||||
<!-- !parallelism-input -->
|
<!-- !parallelism-input -->
|
||||||
<!-- delay-input -->
|
<!-- delay-input -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="update-delay" class="col-sm-3 col-lg-1 control-label text-left">Delay</label>
|
<label for="update-delay" class="col-sm-3 col-lg-1 control-label text-left">
|
||||||
|
Delay
|
||||||
|
<portainer-tooltip position="bottom" message="Supported format examples: 1h, 5m, 10s, 1000ms, 15us, 60ns."></portainer-tooltip>
|
||||||
|
</label>
|
||||||
<div class="col-sm-4 col-lg-3">
|
<div class="col-sm-4 col-lg-3">
|
||||||
<input type="number" class="form-control" ng-model="formValues.UpdateDelay" id="update-delay" placeholder="e.g. 10">
|
<input type="text" class="form-control" ng-model="formValues.UpdateDelay" id="update-delay" placeholder="e.g. 1m" ng-pattern="/^([0-9]+)(h|m|s|ms|us|ns)$/i">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-5">
|
<div class="col-sm-5">
|
||||||
<p class="small text-muted">
|
<p class="small text-muted">
|
||||||
Amount of time between updates. Time in seconds.
|
Amount of time between updates expressed by a number followed by unit (ns|us|ms|s|m|h). Example: 1m.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -19,11 +19,11 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>Update Delay</td>
|
<td>Update Delay</td>
|
||||||
<td>
|
<td>
|
||||||
<input class="input-sm" type="number" ng-model="service.UpdateDelay" ng-change="updateServiceAttribute(service, 'UpdateDelay')" ng-disabled="isUpdating"/>
|
<input class="input-sm" type="text" ng-model="service.UpdateDelay" ng-change="updateServiceAttribute(service, 'UpdateDelay')" ng-pattern="/^([0-9]+)(h|m|s|ms|us|ns)$/i" ng-disabled="isUpdating"/>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<p class="small text-muted" style="margin-top: 10px;">
|
<p class="small text-muted" style="margin-top: 10px;">
|
||||||
Amount of time between updates. Time in seconds.
|
Amount of time between updates expressed by a number followed by unit (ns|us|ms|s|m|h). Example: 1m.
|
||||||
</p>
|
</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -244,7 +244,7 @@ function ($q, $scope, $transition$, $state, $location, $timeout, $anchorScroll,
|
||||||
|
|
||||||
config.UpdateConfig = {
|
config.UpdateConfig = {
|
||||||
Parallelism: service.UpdateParallelism,
|
Parallelism: service.UpdateParallelism,
|
||||||
Delay: service.UpdateDelay * 1000000000,
|
Delay: ServiceHelper.translateHumanDurationToNanos(service.UpdateDelay),
|
||||||
FailureAction: service.UpdateFailureAction,
|
FailureAction: service.UpdateFailureAction,
|
||||||
Order: service.UpdateOrder
|
Order: service.UpdateOrder
|
||||||
};
|
};
|
||||||
|
@ -324,7 +324,7 @@ function ($q, $scope, $transition$, $state, $location, $timeout, $anchorScroll,
|
||||||
function transformDurations(service) {
|
function transformDurations(service) {
|
||||||
service.RestartDelay = service.RestartDelay / 1000000000 || 5;
|
service.RestartDelay = service.RestartDelay / 1000000000 || 5;
|
||||||
service.RestartWindow = service.RestartWindow / 1000000000 || 0;
|
service.RestartWindow = service.RestartWindow / 1000000000 || 0;
|
||||||
service.UpdateDelay = service.UpdateDelay / 1000000000 || 0;
|
service.UpdateDelay = ServiceHelper.translateNanosToHumanDuration(service.UpdateDelay) || '0s';
|
||||||
}
|
}
|
||||||
|
|
||||||
function initView() {
|
function initView() {
|
||||||
|
|
|
@ -141,5 +141,55 @@ angular.module('portainer.helpers').factory('ServiceHelper', [function ServiceHe
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
helper.translateHumanDurationToNanos = function(humanDuration) {
|
||||||
|
var nanos = 0;
|
||||||
|
var regex = /^([0-9]+)(h|m|s|ms|us|ns)$/i;
|
||||||
|
var matches = humanDuration.match(regex);
|
||||||
|
|
||||||
|
if (matches !== null && matches.length === 3) {
|
||||||
|
var duration = parseInt(matches[1], 10);
|
||||||
|
var unit = matches[2];
|
||||||
|
// Moment.js cannot use micro or nanoseconds
|
||||||
|
switch (unit) {
|
||||||
|
case 'ns':
|
||||||
|
nanos = duration;
|
||||||
|
break;
|
||||||
|
case 'us':
|
||||||
|
nanos = duration * 1000;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
nanos = moment.duration(duration, unit).asMilliseconds() * 1000000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nanos;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Convert nanoseconds to the higher unit possible
|
||||||
|
// e.g 1840 nanoseconds = 1804ns
|
||||||
|
// e.g 300000000000 nanoseconds = 5m
|
||||||
|
// e.g 3510000000000 nanoseconds = 3510s
|
||||||
|
// e.g 3540000000000 nanoseconds = 59m
|
||||||
|
// e.g 3600000000000 nanoseconds = 1h
|
||||||
|
|
||||||
|
helper.translateNanosToHumanDuration = function(nanos) {
|
||||||
|
var humanDuration = '0s';
|
||||||
|
|
||||||
|
var conversionFromNano = {};
|
||||||
|
conversionFromNano['ns'] = 1;
|
||||||
|
conversionFromNano['us'] = conversionFromNano['ns'] * 1000;
|
||||||
|
conversionFromNano['ms'] = conversionFromNano['us'] * 1000;
|
||||||
|
conversionFromNano['s'] = conversionFromNano['ms'] * 1000;
|
||||||
|
conversionFromNano['m'] = conversionFromNano['s'] * 60;
|
||||||
|
conversionFromNano['h'] = conversionFromNano['m'] * 60;
|
||||||
|
|
||||||
|
Object.keys(conversionFromNano).forEach(function(unit) {
|
||||||
|
if ( nanos % conversionFromNano[unit] === 0 && (nanos / conversionFromNano[unit]) > 0) {
|
||||||
|
humanDuration = (nanos / conversionFromNano[unit]) + unit;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return humanDuration;
|
||||||
|
};
|
||||||
|
|
||||||
return helper;
|
return helper;
|
||||||
}]);
|
}]);
|
||||||
|
|
Loading…
Reference in New Issue