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