github.com/emate/nomad@v0.8.2-wo-binpacking/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        {
    22          taskStateId: state.id,
    23        },
    24      ].compact();
    25  
    26      const events = server.createList(...props);
    27  
    28      state.update({
    29        eventIds: events.mapBy('id'),
    30      });
    31    },
    32  });