Commit 3a0613cf by Vladislav

Merge branch 'master' into ticket_19473

2 parents 76e0f902 9482d9dc
......@@ -48,7 +48,7 @@ class AdGroupsLoadUpdated extends Command
*/
public function handle()
{
$adGroups = AdGroup::forUpdatedSelf()->get();
$adGroups = AdGroup::has('campaignForEnabledForManaged')->forUpdatedSelf()->get();
if (!$adGroups->count()) {
return;
}
......
......@@ -82,6 +82,7 @@ class CampaignsCheckUpdatedChildrenAdGroups extends Command
'FieldNames' => [
'AdGroupIds',
],
'Timestamp' => $token->check_changes_ad_group_at->toIso8601ZuluString(),
]);
}
......
......@@ -42,7 +42,7 @@ class CampaignsLoadGroups extends Command
*/
public function handle()
{
$campaigns = Campaigns::forGroupsLoadable()->get();
$campaigns = Campaigns::forManaged()->forEnabled()->forGroupsLoadable()->get();
if (!$campaigns->count()) {
return;
}
......
......@@ -58,22 +58,17 @@ class ProcessCallAPI implements ShouldQueue
}
}
$response = $api->execute();
try{
$limits->acceptRezerv($this->limitId, new HeaderLimits($response->headers()));
}catch(\Exception $e){
Log::debug($e);
Log::debug($response->headers());
}
$limits->acceptRezerv($this->limitId, new HeaderLimits($response->headers()));
//TODO: обработать результат.
// если не хватило баллов на все что хотели запросить, то в очередь отправляем новый запрос на получение новых данных
AdsHandler::getInstance($this->api)->handle($response);
} catch (\Exception $e) {
\Log::debug($e);
//TODO: надо отдельно выделить ошибки вызовов, за которые списываются баллы
//https://yandex.ru/dev/direct/doc/dg/concepts/errors.html
Log::debug($e);
$limits->removeRezerv($this->limitId);
throw $e;
}
}
}
......@@ -29,6 +29,7 @@ use Illuminate\Support\Collection;
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\Campaigns $campaign
* @property-read \App\Models\Campaigns|null $campaignForEnabledForManaged
* @property-read \Illuminate\Database\Eloquent\Collection|GoalAdGroup[] $goalGroups
* @property-read int|null $goal_groups_count
* @method static Builder|AdGroup forUpdatedSelf()
......@@ -194,4 +195,9 @@ class AdGroup extends Model
return $this->belongsTo(Campaigns::class, 'campaign_id');
}
public function campaignForEnabledForManaged()
{
return $this->campaign()->forEnabled()->forManaged();
}
}
......@@ -16,6 +16,9 @@ use Illuminate\Support\Facades\Log;
class CheckChanges extends DirectRequest
{
protected $max_count = -1;
protected $max_count_CampaignIds = 3000;
protected $max_count_AdGroupIds = 10000;
protected $max_count_AdIds = 50000;
public function call($params = null)
{
......@@ -54,6 +57,11 @@ class CheckChanges extends DirectRequest
public function handle($response)
{
if (!isset($response['result'])) {
Log::debug($response);
return;
}
if (isset($response['result']['NotFound'])) {
Log::debug($response['result']['NotFound']);
}
......@@ -62,6 +70,7 @@ class CheckChanges extends DirectRequest
Log::debug($response['result']['Unprocessed']);
}
if (isset($response['result']['Modified']['AdGroupIds'])) {
foreach ($response['result']['Modified']['AdGroupIds'] as $ad_group_id) {
......@@ -105,6 +114,7 @@ class CheckChanges extends DirectRequest
]);
}
$this->getToken()->update([
'check_changes_ad_group' => Carbon::parse($response['result']['Timestamp']),
]);
......@@ -124,15 +134,15 @@ class CheckChanges extends DirectRequest
$this->setMethod('check');
if (isset($params['CampaignIds'])){
$this->max_count = 3000;
$this->max_count = $this->max_count_CampaignIds;
}
if (isset($params['AdGroupIds'])){
$this->max_count = 10000;
$this->max_count = $this->max_count_AdGroupIds;
}
if (isset($params['AdIds'])){
$this->max_count = 50000;
$this->max_count = $this->max_count_AdIds;
}
$this->setParams($params);
......
......@@ -16,6 +16,7 @@ use Illuminate\Support\Facades\Log;
class GetAdGroups extends DirectRequest
{
protected $max_count = 10000;
protected $max_count_CampaignIds = 10;
function call($params = null)
{
......@@ -83,7 +84,7 @@ class GetAdGroups extends DirectRequest
foreach ($response['result']['AdGroups'] as $ad_group) {
$campaign = $campaigns->get($ad_group['CampaignId']);
$campaign = $campaigns->firstWhere('external_id', $ad_group['CampaignId']);
if (!$campaign)
continue;
......@@ -156,6 +157,9 @@ class GetAdGroups extends DirectRequest
],
];
if (isset($filter['CampaignIds'])) {
$this->max_count = $this->max_count_CampaignIds;
$params['SelectionCriteria'] = [
'CampaignIds' => $filter['CampaignIds'],
];
......
......@@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Log;
class GetCampaigns extends DirectRequest
{
protected $max_count = 10000;
protected $max_count = 1000;
protected $timestamp;
public function call($params = null)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!