2019-11-12 01:05:47 +00:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { computed } from '@ember/object';
|
|
|
|
import { equal } from '@ember/object/computed';
|
|
|
|
import { computed as overridable } from 'ember-overridable-computed';
|
|
|
|
import { task } from 'ember-concurrency';
|
2019-12-13 20:24:13 +00:00
|
|
|
import Duration from 'duration-js';
|
2019-11-12 01:05:47 +00:00
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
tagName: '',
|
|
|
|
|
|
|
|
client: null,
|
2020-01-30 21:40:17 +00:00
|
|
|
isDisabled: false,
|
2019-11-12 01:05:47 +00:00
|
|
|
|
|
|
|
onError() {},
|
|
|
|
onDrain() {},
|
|
|
|
|
|
|
|
parseError: '',
|
|
|
|
|
|
|
|
deadlineEnabled: false,
|
|
|
|
forceDrain: false,
|
|
|
|
drainSystemJobs: true,
|
|
|
|
|
|
|
|
selectedDurationQuickOption: overridable(function() {
|
2019-11-12 22:18:26 +00:00
|
|
|
return this.durationQuickOptions[0];
|
2019-11-12 01:05:47 +00:00
|
|
|
}),
|
|
|
|
|
|
|
|
durationIsCustom: equal('selectedDurationQuickOption.value', 'custom'),
|
|
|
|
customDuration: '',
|
|
|
|
|
|
|
|
durationQuickOptions: computed(() => [
|
|
|
|
{ label: '1 Hour', value: '1h' },
|
|
|
|
{ label: '4 Hours', value: '4h' },
|
|
|
|
{ label: '8 Hours', value: '8h' },
|
|
|
|
{ label: '12 Hours', value: '12h' },
|
|
|
|
{ label: '1 Day', value: '1d' },
|
|
|
|
{ label: 'Custom', value: 'custom' },
|
|
|
|
]),
|
|
|
|
|
|
|
|
deadline: computed(
|
|
|
|
'deadlineEnabled',
|
|
|
|
'durationIsCustom',
|
|
|
|
'customDuration',
|
|
|
|
'selectedDurationQuickOption.value',
|
|
|
|
function() {
|
|
|
|
if (!this.deadlineEnabled) return 0;
|
|
|
|
if (this.durationIsCustom) return this.customDuration;
|
|
|
|
return this.selectedDurationQuickOption.value;
|
|
|
|
}
|
|
|
|
),
|
|
|
|
|
|
|
|
drain: task(function*(close) {
|
|
|
|
if (!this.client) return;
|
2019-11-19 06:36:07 +00:00
|
|
|
const isUpdating = this.client.isDraining;
|
2019-11-12 01:05:47 +00:00
|
|
|
|
|
|
|
let deadline;
|
|
|
|
try {
|
2019-12-13 20:24:13 +00:00
|
|
|
deadline = new Duration(this.deadline).nanoseconds();
|
2019-11-12 01:05:47 +00:00
|
|
|
} catch (err) {
|
2019-12-13 20:24:13 +00:00
|
|
|
this.set('parseError', err.message);
|
2019-11-12 01:05:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const spec = {
|
|
|
|
Deadline: deadline,
|
|
|
|
IgnoreSystemJobs: !this.drainSystemJobs,
|
|
|
|
};
|
|
|
|
|
|
|
|
close();
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (this.forceDrain) {
|
|
|
|
yield this.client.forceDrain(spec);
|
|
|
|
} else {
|
|
|
|
yield this.client.drain(spec);
|
|
|
|
}
|
2019-11-19 06:36:07 +00:00
|
|
|
this.onDrain(isUpdating);
|
2019-11-12 01:05:47 +00:00
|
|
|
} catch (err) {
|
|
|
|
this.onError(err);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
preventDefault(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
},
|
|
|
|
});
|