github.com/hernad/nomad@v1.6.112/ui/app/models/task-state.js (about)

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