github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/app/models/task-state.js (about) 1 import { computed } from '@ember/object'; 2 import { alias, none, and } from '@ember/object/computed'; 3 import Fragment from 'ember-data-model-fragments/fragment'; 4 import { attr } from '@ember-data/model'; 5 import { fragment, fragmentOwner, fragmentArray } from 'ember-data-model-fragments/attributes'; 6 import classic from 'ember-classic-decorator'; 7 8 @classic 9 export default class TaskState extends Fragment { 10 @fragmentOwner() allocation; 11 12 @attr('string') name; 13 @attr('string') state; 14 @attr('date') startedAt; 15 @attr('date') finishedAt; 16 @attr('boolean') failed; 17 18 @none('finishedAt') isActive; 19 @and('isActive', 'allocation.isRunning') isRunning; 20 21 @computed('task.kind') 22 get isConnectProxy() { 23 return (this.get('task.kind') || '').startsWith('connect-proxy:'); 24 } 25 26 @computed('name', 'allocation.taskGroup.tasks.[]') 27 get task() { 28 const tasks = this.get('allocation.taskGroup.tasks'); 29 return tasks && tasks.findBy('name', this.name); 30 } 31 32 @alias('task.driver') driver; 33 34 // TaskState represents a task running on a node, so in addition to knowing the 35 // driver via the task, the health of the driver is also known via the node 36 @computed('task.driver', 'allocation.node.drivers.[]') 37 get driverStatus() { 38 const nodeDrivers = this.get('allocation.node.drivers') || []; 39 return nodeDrivers.findBy('name', this.get('task.driver')); 40 } 41 42 @fragment('resources') resources; 43 @fragmentArray('task-event') events; 44 45 @computed('state') 46 get stateClass() { 47 const classMap = { 48 pending: 'is-pending', 49 running: 'is-primary', 50 finished: 'is-complete', 51 failed: 'is-error', 52 }; 53 54 return classMap[this.state] || 'is-dark'; 55 } 56 57 restart() { 58 return this.allocation.restart(this.name); 59 } 60 }