Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Письменов Дмитрий Иванович
/
yourroomads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3a0613cf
authored
Jun 09, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into ticket_19473
2 parents
76e0f902
9482d9dc
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
13 deletions
app/Console/Commands/AdGroupsLoadUpdated.php
app/Console/Commands/CampaignsCheckUpdatedChildrenAdGroups.php
app/Console/Commands/CampaignsLoadGroups.php
app/Jobs/ProcessCallAPI.php
app/Models/AdGroup.php
app/Service/Requests/Direct/CheckChanges.php
app/Service/Requests/Direct/GetAdGroups.php
app/Service/Requests/Direct/GetCampaigns.php
app/Console/Commands/AdGroupsLoadUpdated.php
View file @
3a0613c
...
...
@@ -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
;
}
...
...
app/Console/Commands/CampaignsCheckUpdatedChildrenAdGroups.php
View file @
3a0613c
...
...
@@ -82,6 +82,7 @@ class CampaignsCheckUpdatedChildrenAdGroups extends Command
'FieldNames'
=>
[
'AdGroupIds'
,
],
'Timestamp'
=>
$token
->
check_changes_ad_group_at
->
toIso8601ZuluString
(),
]);
}
...
...
app/Console/Commands/CampaignsLoadGroups.php
View file @
3a0613c
...
...
@@ -42,7 +42,7 @@ class CampaignsLoadGroups extends Command
*/
public
function
handle
()
{
$campaigns
=
Campaigns
::
forGroupsLoadable
()
->
get
();
$campaigns
=
Campaigns
::
for
Managed
()
->
forEnabled
()
->
for
GroupsLoadable
()
->
get
();
if
(
!
$campaigns
->
count
())
{
return
;
}
...
...
app/Jobs/ProcessCallAPI.php
View file @
3a0613c
...
...
@@ -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
());
}
//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
;
}
}
}
app/Models/AdGroup.php
View file @
3a0613c
...
...
@@ -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
();
}
}
app/Service/Requests/Direct/CheckChanges.php
View file @
3a0613c
...
...
@@ -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
);
...
...
app/Service/Requests/Direct/GetAdGroups.php
View file @
3a0613c
...
...
@@ -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'
],
];
...
...
app/Service/Requests/Direct/GetCampaigns.php
View file @
3a0613c
...
...
@@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Log;
class
GetCampaigns
extends
DirectRequest
{
protected
$max_count
=
1000
0
;
protected
$max_count
=
1000
;
protected
$timestamp
;
public
function
call
(
$params
=
null
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment