Commit be040e48 by Евгений

Улучшение #19474

Синхронизация фраз и групп
1 parent 6a102696
......@@ -46,7 +46,6 @@ class AdGroupsAdd extends Command
->get();
foreach ($tokens as $token) {
$token->load([
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForNotExternal' => function (HasMany $query) {
return $query->has('group');
......
......@@ -60,11 +60,13 @@ class ProcessCallAPI implements ShouldQueue
}
}
$response = $api->execute();
$handler = AdsHandler::getInstance($this->api);
$handler->checkError($response);
$limits->acceptRezerv($this->limitId, new HeaderLimits($response->headers()));
//TODO: обработать результат.
// если не хватило баллов на все что хотели запросить, то в очередь отправляем новый запрос на получение новых данных
AdsHandler::getInstance($this->api)->handle($response);
$handler->handle($response);
} catch (\Exception $e) {
//TODO: надо отдельно выделить ошибки вызовов, за которые списываются баллы
//https://yandex.ru/dev/direct/doc/dg/concepts/errors.html
......
......@@ -3,6 +3,7 @@ namespace App\Service\API;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
class YandexDirect extends API{
private $url = 'https://oauth.yandex.ru/token';
......@@ -42,9 +43,12 @@ class YandexDirect extends API{
public function execute(): Response
{
return Http::withBody($this->request->getBody(), 'none')
// Log::debug($this->request->getBody());
$result = Http::withBody($this->request->getBody(), 'none')
->withHeaders($this->request->getHeaders())
->withToken($this->request->getToken()->token)
->post($this->request->getUrl());
// Log::debug($result->json());
return $result;
}
}
......@@ -12,4 +12,11 @@ class DirectHandler extends AdsHandler
{
$this->response = $response->json();
}
public function checkError($response){
$this->parse($response);
if ($this->response['error']){
throw new \Exception($this->response['error']['error_detail']);
}
}
}
......@@ -23,6 +23,7 @@ class AddAdGroups extends DirectRequest
public function call($params = null)
{
$this->requestPrepare($params);
Log::debug($this->getParams());
$process = new ProcessCallLimitedAPI($this);
dispatch($process)->onQueue('limits');
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!