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';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { tagName } from '@ember-decorators/component';
|
|
|
|
import classic from 'ember-classic-decorator';
|
2018-04-19 17:14:59 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
@tagName('')
|
|
|
|
export default class Title extends Component {
|
|
|
|
job = null;
|
|
|
|
title = null;
|
2018-04-19 17:14:59 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
handleError() {}
|
2018-04-19 17:14:59 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@task(function*() {
|
2018-08-24 20:20:29 +00:00
|
|
|
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',
|
2021-01-28 00:40:51 +00:00
|
|
|
description: messageFromAdapterError(err, 'stop jobs'),
|
2018-08-24 20:20:29 +00:00
|
|
|
});
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
})
|
|
|
|
stopJob;
|
2018-08-24 20:20:29 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@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) {
|
2019-03-26 07:46:44 +00:00
|
|
|
this.handleError({
|
2018-08-24 20:20:29 +00:00
|
|
|
title: 'Could Not Start Job',
|
2021-01-28 00:40:51 +00:00
|
|
|
description: messageFromAdapterError(err, 'start jobs'),
|
2018-08-24 20:20:29 +00:00
|
|
|
});
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
})
|
|
|
|
startJob;
|
|
|
|
}
|