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