function main(){
console.time('main')
const skip = [ 0,20/*,40,60,80 */]
for (const k in skip){
getIds(skip[k])
}
console.timeEnd('main')
}
async function getIds(skip) {
console.time('getIds')
const ids = await axios.get(`https://dummyjson.com/users?limit=20&skip=${skip}&select=firstName,age`)
const idsPromises = ids.data.users.map(async user => {
const postPromise = axios.get(`https://dummyjson.com/users/${user.id}/posts?select=id,title&limit=1`)
const todoPromise = axios.get(`https://dummyjson.com/users/${user.id}/todos?select=id,todo&limit=1`)
const post = await postPromise
if (post.data.posts.length > 0){
const savedPost = await Post.upsert(post.data.posts[0])
}
const todo = await todoPromise
if (todo.data.todos.length > 0) {
const savedTodo = await Todo.upsert(todo.data.todos[0])
}
})
Promise.all(idsPromises).then(console.timeEnd('getIds'))
}
main()
Предположим что есть 20 эндпоинтов на стороннем APIИсходя из этого - проблема не в базе, а в получении 4к запросов за наиболее короткое время.
[2023-04-20 22:37:02] local.ERROR: pcntl_signal() has been disabled for security reasons {"exception":"[object] (ErrorException(code: 0): pcntl_signal() has been disabled for security reasons at /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Queue/Worker.php:643)
[stacktrace]
#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'pcntl_signal() ...', '/var/www/www-ro...', 643, Array)
#1 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Queue/Worker.php(643): pcntl_signal(15, Object(Closure))
#2 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Queue/Worker.php(120): Illuminate\\Queue\\Worker->listenForSignals()
#3 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(116): Illuminate\\Queue\\Worker->daemon('null', 'default', Object(Illuminate\\Queue\\WorkerOptions))
#4 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(100): Illuminate\\Queue\\Console\\WorkCommand->runWorker('null', 'default')
#5 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle()
#6 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#7 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#8 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#9 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Container/Container.php(596): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#10 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
#11 /var/www/www-root/data/www//vendor/symfony/console/Command/Command.php(258): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#12 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#13 /var/www/www-root/data/www//vendor/symfony/console/Application.php(920): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#14 /var/www/www-root/data/www//vendor/symfony/console/Application.php(266): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#15 /var/www/www-root/data/www//vendor/symfony/console/Application.php(142): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#17 /var/www/www-root/data/www//vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 /var/www/www-root/data/www//artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 {main}
"}