accountOpQueueModel = new \Models\Queue\AccountOperationQueue($actionType); $this->apiKeysModel = new \Models\ApiKeys(); $this->controller = new \Controllers\Admin\Enrichment\Data(); } public function processQueue(): void { if ($this->accountOpQueueModel->isExecuting() && !$this->accountOpQueueModel->unclog()) { $this->log('Enrchment queue is already being executed by another cron job.'); } else { $this->processItems($this->accountOpQueueModel); } } protected function processItem(array $item): void { $start = time(); $apiKey = $item['key']; $userId = $item['event_account']; $subscriptionKey = $this->apiKeysModel->getKeyById($apiKey)->token; $entities = $this->controller->getNotCheckedEntitiesByUserId($userId, $apiKey); // TODO: check key ? $this->log(sprintf('Items to enrich for account %s: %s.', $userId, json_encode($entities))); $summary = []; $success = 0; $failed = 0; foreach ($entities as $type => $items) { if (count($items)) { $summary[$type] = count($items); } foreach ($items as $item) { $result = $this->controller->enrichEntity($type, null, $item, $apiKey, $subscriptionKey); if (isset($result['ERROR_CODE'])) { $failed += 1; } else { $success += 1; } } } // TODO: if failed !== 0 add to queue again? // TODO: recalculate score after all? $this->log(sprintf('Enrichment for account %s: %s enriched, %s failed in %s s (%s).', $userId, $success, $failed, time() - $start, json_encode($summary))); } }