github.com/hernad/nomad@v1.6.112/ui/app/routes/jobs/job/task-group.js (about)

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