github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/routes/jobs/job/task-group.js (about) 1 import Route from '@ember/routing/route'; 2 import { collect } from '@ember/object/computed'; 3 import EmberError from '@ember/error'; 4 import { resolve, all } from 'rsvp'; 5 import { 6 watchRecord, 7 watchRelationship, 8 } from 'nomad-ui/utils/properties/watch'; 9 import WithWatchers from 'nomad-ui/mixins/with-watchers'; 10 import notifyError from 'nomad-ui/utils/notify-error'; 11 import { inject as service } from '@ember/service'; 12 13 export default class TaskGroupRoute extends Route.extend(WithWatchers) { 14 @service store; 15 16 model({ name }) { 17 const job = this.modelFor('jobs.job'); 18 19 // If there is no job, then there is no task group. 20 // Let the job route handle the 404. 21 if (!job) return; 22 23 // If the job is a partial (from the list request) it won't have task 24 // groups. Reload the job to ensure task groups are present. 25 const reload = job.get('isPartial') ? job.reload() : resolve(); 26 return reload 27 .then(() => { 28 const taskGroup = job.get('taskGroups').findBy('name', name); 29 if (!taskGroup) { 30 const err = new EmberError( 31 `Task group ${name} for job ${job.get('name')} not found` 32 ); 33 err.code = '404'; 34 throw err; 35 } 36 37 // Refresh job allocations before-hand (so page sort works on load) 38 return all([ 39 job.hasMany('allocations').reload(), 40 job.get('scaleState'), 41 ]).then(() => taskGroup); 42 }) 43 .catch(notifyError(this)); 44 } 45 46 startWatchers(controller, model) { 47 if (model) { 48 const job = model.get('job'); 49 controller.set('watchers', { 50 job: this.watchJob.perform(job), 51 summary: this.watchSummary.perform(job.get('summary')), 52 scale: this.watchScale.perform(job.get('scaleState')), 53 allocations: this.watchAllocations.perform(job), 54 latestDeployment: 55 job.get('supportsDeployments') && 56 this.watchLatestDeployment.perform(job), 57 }); 58 } 59 } 60 61 @watchRecord('job') watchJob; 62 @watchRecord('job-summary') watchSummary; 63 @watchRecord('job-scale') watchScale; 64 @watchRelationship('allocations') watchAllocations; 65 @watchRelationship('latestDeployment') watchLatestDeployment; 66 67 @collect( 68 'watchJob', 69 'watchSummary', 70 'watchScale', 71 'watchAllocations', 72 'watchLatestDeployment' 73 ) 74 watchers; 75 }