Switch stop/run job actions to EC tasks

This commit is contained in:
Michael Lange
2018-08-24 13:20:29 -07:00
parent 1b481a3b72
commit f09e9a41bc
2 changed files with 34 additions and 42 deletions

View File

@@ -1,4 +1,5 @@
import Component from '@ember/component';
import { task } from 'ember-concurrency';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
export default Component.extend({
@@ -9,46 +10,37 @@ export default Component.extend({
handleError() {},
actions: {
stopJob() {
this.get('job')
.stop()
.catch(() => {
this.get('handleError')({
title: 'Could Not Stop Job',
description: 'Your ACL token does not grant permission to stop jobs.',
});
});
},
stopJob: task(function*() {
try {
yield this.get('job').stop();
} catch (err) {
this.get('handleError')({
title: 'Could Not Stop Job',
description: 'Your ACL token does not grant permission to stop jobs.',
});
}
}),
startJob() {
const job = this.get('job');
job
.fetchRawDefinition()
.then(definition => {
// A stopped job will have this Stop = true metadata
// If Stop is true when submitted to the cluster, the job
// won't transition from the Dead to Running state.
delete definition.Stop;
job.set('_newDefinition', JSON.stringify(definition));
})
.then(() => {
return job.parse();
})
.then(() => {
return job.update();
})
.catch(err => {
let message = messageFromAdapterError(err);
if (!message || message === 'Forbidden') {
message = 'Your ACL token does not grant permission to stop jobs.';
}
startJob: task(function*() {
const job = this.get('job');
const definition = yield job.fetchRawDefinition();
this.get('handleError')({
title: 'Could Not Start Job',
description: message,
});
});
},
},
delete definition.Stop;
job.set('_newDefinition', JSON.stringify(definition));
try {
yield job.parse();
yield job.update();
} catch (err) {
let message = messageFromAdapterError(err);
if (!message || message === 'Forbidden') {
message = 'Your ACL token does not grant permission to stop jobs.';
}
this.get('handleError')({
title: 'Could Not Start Job',
description: message,
});
}
}),
});

View File

@@ -9,7 +9,7 @@
cancelText="Cancel"
confirmText="Yes, Stop"
confirmationMessage="Are you sure you want to stop this job?"
onConfirm=(action "stopJob")}}
onConfirm=(perform stopJob)}}
{{else}}
{{two-step-button
data-test-start
@@ -17,6 +17,6 @@
cancelText="Cancel"
confirmText="Yes, Start"
confirmationMessage="Are you sure you want to start this job?"
onConfirm=(action "startJob")}}
onConfirm=(perform startJob)}}
{{/if}}
</h1>