mirror of
https://github.com/kemko/nomad.git
synced 2026-01-10 04:15:41 +03:00
Switch stop/run job actions to EC tasks
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user