github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/ui/mirage/factories/task-state.js (about)

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