-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscript.js
50 lines (40 loc) · 885 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const faker = require('faker')
const container = require('./src/container')
async function script () {
const {
logger,
usersService,
todosService,
} = container.cradle
async function task () {
const user = await usersService.createUser({
name: faker.name.findName(),
email: faker.internet.email(),
})
const { id } = user
await todosService.createTodo({
todo: faker.hacker.phrase(),
userId: id,
})
}
try {
logger.info({
message: 'Running script populating tables',
})
const tasks = []
for (let i = 0; i < 100; i += 1) {
tasks.push(task())
}
await Promise.all(tasks)
logger.info({
message: 'Done',
})
} catch (error) {
logger.fatal({
message: 'Unexpected script behavior',
error: error.message,
stack: error.stack,
})
}
}
script()