I am migrating some nodes from an API.
The API only accepts 60 requests per minute.
So it means if 60 items are imported in a minute, all other items will not be imported because the API will return 429 error code in that case.
So on the next cron, the same 60 items will be processed and will be updated. All the other items will never be imported.
function mymodule_cron() {
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = $this->migrationPluginManager->createInstance($migration_id);
$migration->getIdMap()->prepareUpdate();
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();
}
So what should I do in this case to import all the items?
Is there any queue functionality with the cron which executes migration? So that I can tell to execute 60 items per queue and execute one queue per minute, something like that?
Update:
$request = $this->httpClient->get($url, [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $this->token,
],
]);
$news_item = json_decode($request->getBody(), TRUE);
$source = $migration->getSourceConfiguration();
$source['data_rows'] = $news_item;
$migration->set('source', $source);
They are 300+ items.