github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/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 useMessagePassthru: false, 18 19 afterCreate(state, server) { 20 const props = [ 21 'task-event', 22 faker.random.number({ min: 1, max: 10 }), 23 state.useMessagePassthru && 'messagePassthru', 24 { 25 taskStateId: state.id, 26 }, 27 ].compact(); 28 29 const events = server.createList(...props); 30 31 state.update({ 32 eventIds: events.mapBy('id'), 33 }); 34 }, 35 });