github.com/manicqin/nomad@v0.9.5/ui/app/components/job-page/parts/title.js (about) 1 import Component from '@ember/component'; 2 import { task } from 'ember-concurrency'; 3 import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error'; 4 5 export default Component.extend({ 6 tagName: '', 7 8 job: null, 9 title: null, 10 11 handleError() {}, 12 13 stopJob: task(function*() { 14 try { 15 const job = this.job; 16 yield job.stop(); 17 // Eagerly update the job status to avoid flickering 18 this.job.set('status', 'dead'); 19 } catch (err) { 20 this.handleError({ 21 title: 'Could Not Stop Job', 22 description: 'Your ACL token does not grant permission to stop jobs.', 23 }); 24 } 25 }), 26 27 startJob: task(function*() { 28 const job = this.job; 29 const definition = yield job.fetchRawDefinition(); 30 31 delete definition.Stop; 32 job.set('_newDefinition', JSON.stringify(definition)); 33 34 try { 35 yield job.parse(); 36 yield job.update(); 37 // Eagerly update the job status to avoid flickering 38 job.set('status', 'running'); 39 } catch (err) { 40 let message = messageFromAdapterError(err); 41 if (!message || message === 'Forbidden') { 42 message = 'Your ACL token does not grant permission to stop jobs.'; 43 } 44 45 this.handleError({ 46 title: 'Could Not Start Job', 47 description: message, 48 }); 49 } 50 }), 51 });