2018-04-19 17:14:59 +00:00
|
|
|
import Component from '@ember/component';
|
2018-08-24 20:20:29 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
2018-08-24 20:17:45 +00:00
|
|
|
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
|
2018-04-19 17:14:59 +00:00
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
tagName: '',
|
|
|
|
|
|
|
|
job: null,
|
|
|
|
title: null,
|
|
|
|
|
|
|
|
handleError() {},
|
|
|
|
|
2018-08-24 20:20:29 +00:00
|
|
|
stopJob: task(function*() {
|
|
|
|
try {
|
2019-03-26 07:46:44 +00:00
|
|
|
const job = this.job;
|
2018-08-24 21:02:13 +00:00
|
|
|
yield job.stop();
|
|
|
|
// Eagerly update the job status to avoid flickering
|
|
|
|
this.job.set('status', 'dead');
|
2018-08-24 20:20:29 +00:00
|
|
|
} catch (err) {
|
2019-03-26 07:46:44 +00:00
|
|
|
this.handleError({
|
2018-08-24 20:20:29 +00:00
|
|
|
title: 'Could Not Stop Job',
|
|
|
|
description: 'Your ACL token does not grant permission to stop jobs.',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
startJob: task(function*() {
|
2019-03-26 07:46:44 +00:00
|
|
|
const job = this.job;
|
2018-08-24 20:20:29 +00:00
|
|
|
const definition = yield job.fetchRawDefinition();
|
|
|
|
|
|
|
|
delete definition.Stop;
|
|
|
|
job.set('_newDefinition', JSON.stringify(definition));
|
|
|
|
|
|
|
|
try {
|
|
|
|
yield job.parse();
|
|
|
|
yield job.update();
|
2018-08-24 21:02:13 +00:00
|
|
|
// Eagerly update the job status to avoid flickering
|
|
|
|
job.set('status', 'running');
|
2018-08-24 20:20:29 +00:00
|
|
|
} catch (err) {
|
|
|
|
let message = messageFromAdapterError(err);
|
|
|
|
if (!message || message === 'Forbidden') {
|
|
|
|
message = 'Your ACL token does not grant permission to stop jobs.';
|
|
|
|
}
|
|
|
|
|
2019-03-26 07:46:44 +00:00
|
|
|
this.handleError({
|
2018-08-24 20:20:29 +00:00
|
|
|
title: 'Could Not Start Job',
|
|
|
|
description: message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}),
|
2018-04-19 17:14:59 +00:00
|
|
|
});
|