open-nomad/ui/app/components/job-page/parts/title.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.3 KiB
JavaScript
Raw Normal View History

import Component from '@ember/component';
import { task } from 'ember-concurrency';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
@classic
@tagName('')
export default class Title extends Component {
job = null;
title = null;
handleError() {}
2021-12-28 14:45:20 +00:00
@task(function* () {
try {
2019-03-26 07:46:44 +00:00
const job = this.job;
yield job.stop();
// Eagerly update the job status to avoid flickering
this.job.set('status', 'dead');
} catch (err) {
2019-03-26 07:46:44 +00:00
this.handleError({
title: 'Could Not Stop Job',
description: messageFromAdapterError(err, 'stop jobs'),
});
}
})
stopJob;
2021-12-28 14:45:20 +00:00
@task(function* () {
2019-03-26 07:46:44 +00:00
const job = this.job;
const definition = yield job.fetchRawDefinition();
delete definition.Stop;
job.set('_newDefinition', JSON.stringify(definition));
try {
yield job.parse();
yield job.update();
// Eagerly update the job status to avoid flickering
job.set('status', 'running');
} catch (err) {
2019-03-26 07:46:44 +00:00
this.handleError({
title: 'Could Not Start Job',
description: messageFromAdapterError(err, 'start jobs'),
});
}
})
startJob;
}