github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/components/job-page/parts/title.js (about) 1 import Component from '@ember/component'; 2 import { task } from 'ember-concurrency'; 3 import { inject as service } from '@ember/service'; 4 import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error'; 5 import { tagName } from '@ember-decorators/component'; 6 import classic from 'ember-classic-decorator'; 7 8 @classic 9 @tagName('') 10 export default class Title extends Component { 11 @service router; 12 13 job = null; 14 title = null; 15 16 handleError() {} 17 18 @task(function* () { 19 try { 20 const job = this.job; 21 yield job.stop(); 22 // Eagerly update the job status to avoid flickering 23 this.job.set('status', 'dead'); 24 } catch (err) { 25 this.handleError({ 26 title: 'Could Not Stop Job', 27 description: messageFromAdapterError(err, 'stop jobs'), 28 }); 29 } 30 }) 31 stopJob; 32 33 @task(function* () { 34 try { 35 const job = this.job; 36 yield job.purge(); 37 this.flashMessages.add({ 38 title: 'Job Purged', 39 message: `You have purged ${this.job.name}`, 40 type: 'success', 41 destroyOnClick: false, 42 timeout: 5000, 43 }); 44 this.router.transitionTo('jobs'); 45 } catch (err) { 46 this.handleError({ 47 title: 'Error purging job', 48 description: messageFromAdapterError(err, 'purge jobs'), 49 }); 50 } 51 }) 52 purgeJob; 53 54 @task(function* () { 55 const job = this.job; 56 const definition = yield job.fetchRawDefinition(); 57 58 delete definition.Stop; 59 job.set('_newDefinition', JSON.stringify(definition)); 60 61 try { 62 yield job.parse(); 63 yield job.update(); 64 // Eagerly update the job status to avoid flickering 65 job.set('status', 'running'); 66 } catch (err) { 67 this.handleError({ 68 title: 'Could Not Start Job', 69 description: messageFromAdapterError(err, 'start jobs'), 70 }); 71 } 72 }) 73 startJob; 74 }