Commit be040e48 by Евгений

Улучшение #19474

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