github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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 import { tagName } from '@ember-decorators/component'; 5 import classic from 'ember-classic-decorator'; 6 7 @classic 8 @tagName('') 9 export default class Title extends Component { 10 job = null; 11 title = null; 12 13 handleError() {} 14 15 @task(function*() { 16 try { 17 const job = this.job; 18 yield job.stop(); 19 // Eagerly update the job status to avoid flickering 20 this.job.set('status', 'dead'); 21 } catch (err) { 22 this.handleError({ 23 title: 'Could Not Stop Job', 24 description: messageFromAdapterError(err, 'stop jobs'), 25 }); 26 } 27 }) 28 stopJob; 29 30 @task(function*() { 31 const job = this.job; 32 const definition = yield job.fetchRawDefinition(); 33 34 delete definition.Stop; 35 job.set('_newDefinition', JSON.stringify(definition)); 36 37 try { 38 yield job.parse(); 39 yield job.update(); 40 // Eagerly update the job status to avoid flickering 41 job.set('status', 'running'); 42 } catch (err) { 43 this.handleError({ 44 title: 'Could Not Start Job', 45 description: messageFromAdapterError(err, 'start jobs'), 46 }); 47 } 48 }) 49 startJob; 50 }