github.com/manicqin/nomad@v0.9.5/ui/mirage/factories/task-state.js (about)

     1  import { Factory } from 'ember-cli-mirage';
     2  import faker from 'nomad-ui/mirage/faker';
     3  
     4  const TASK_STATUSES = ['pending', 'running', 'finished', 'failed'];
     5  const REF_TIME = new Date();
     6  
     7  export default Factory.extend({
     8    name: () => '!!!this should be set by the allocation that owns this task state!!!',
     9    state: () => faker.helpers.randomize(TASK_STATUSES),
    10    kind: null,
    11    startedAt: () => faker.date.past(2 / 365, REF_TIME),
    12    finishedAt() {
    13      if (['pending', 'running'].includes(this.state)) {
    14        return '0001-01-01T00:00:00Z';
    15      }
    16      return new Date(this.startedAt + Math.random(1000 * 60 * 3) + 50);
    17    },
    18  
    19    afterCreate(state, server) {
    20      const props = [
    21        'task-event',
    22        faker.random.number({ min: 1, max: 3 }),
    23        {
    24          taskStateId: state.id,
    25        },
    26      ].compact();
    27  
    28      const events = server.createList(...props);
    29  
    30      state.update({
    31        eventIds: events.mapBy('id'),
    32      });
    33    },
    34  });