2019-09-26 18:47:07 +00:00
|
|
|
import { Factory } from 'ember-cli-mirage';
|
|
|
|
import faker from 'faker';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
const TASK_STATUSES = ['pending', 'running', 'finished', 'failed'];
|
|
|
|
const REF_TIME = new Date();
|
|
|
|
|
|
|
|
export default Factory.extend({
|
|
|
|
name: () => '!!!this should be set by the allocation that owns this task state!!!',
|
2019-09-26 18:47:07 +00:00
|
|
|
state: faker.helpers.randomize(TASK_STATUSES),
|
2019-09-04 14:39:56 +00:00
|
|
|
kind: null,
|
2017-09-19 14:47:10 +00:00
|
|
|
startedAt: faker.date.past(2 / 365, REF_TIME),
|
|
|
|
finishedAt() {
|
|
|
|
if (['pending', 'running'].includes(this.state)) {
|
|
|
|
return '0001-01-01T00:00:00Z';
|
|
|
|
}
|
|
|
|
return new Date(this.startedAt + Math.random(1000 * 60 * 3) + 50);
|
|
|
|
},
|
|
|
|
|
|
|
|
afterCreate(state, server) {
|
|
|
|
const props = [
|
|
|
|
'task-event',
|
2019-04-12 01:15:35 +00:00
|
|
|
faker.random.number({ min: 1, max: 3 }),
|
2017-09-19 14:47:10 +00:00
|
|
|
{
|
|
|
|
taskStateId: state.id,
|
|
|
|
},
|
|
|
|
].compact();
|
|
|
|
|
|
|
|
const events = server.createList(...props);
|
|
|
|
|
|
|
|
state.update({
|
|
|
|
eventIds: events.mapBy('id'),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|