diff --git a/ui/app/components/job-page/parts/title.js b/ui/app/components/job-page/parts/title.js index a7f079705..d6b4dcbf5 100644 --- a/ui/app/components/job-page/parts/title.js +++ b/ui/app/components/job-page/parts/title.js @@ -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, + }); + } + }), }); diff --git a/ui/app/templates/components/job-page/parts/title.hbs b/ui/app/templates/components/job-page/parts/title.hbs index 6bbd9f9b4..a7cf01876 100644 --- a/ui/app/templates/components/job-page/parts/title.hbs +++ b/ui/app/templates/components/job-page/parts/title.hbs @@ -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}}