Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
139
Issues
139
List
Boards
Labels
Service Desk
Milestones
Merge Requests
46
Merge Requests
46
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Compare Revisions
797d592d559183153279d86b8775accaa17797c1...5cd99f033b8d4e5439384a46c9feebb440cb5a3d
Source
5cd99f033b8d4e5439384a46c9feebb440cb5a3d
Select Git revision
...
Target
797d592d559183153279d86b8775accaa17797c1
Select Git revision
Compare
Commits (3)
(feat): queue runner for completing boosts
· 186b42e9
Marcelo Rivera
authored
6 hours ago
186b42e9
(feat): boost campaigns iterator
· ee60ae69
Marcelo Rivera
authored
5 hours ago
ee60ae69
(feat): BoostCampaigns starter CLI
· 5cd99f03
Marcelo Rivera
authored
5 hours ago
5cd99f03
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
266 additions
and
10 deletions
+266
-10
BoostCampaigns.php
Controllers/Cli/BoostCampaigns.php
+54
-0
Iterator.php
Core/Boost/Campaigns/Iterator.php
+159
-0
Manager.php
Core/Boost/Campaigns/Manager.php
+14
-10
BoostCampaignChecker.php
Core/Queue/Runners/BoostCampaignChecker.php
+29
-0
minds.conf
containers/php-runners/minds.conf
+10
-0
No files found.
Controllers/Cli/BoostCampaigns.php
0 → 100644
View file @
5cd99f03
<?php
namespace
Minds\Controllers\Cli
;
use
DateTime
;
use
Elasticsearch\ClientBuilder
;
use
Minds\Cli
;
use
Minds\Core
;
use
Minds\Core\Di\Di
;
use
Minds\Entities
;
use
Minds\Helpers\Flags
;
use
Minds\Interfaces
;
use
Minds\Core\Rewards\Contributions\UsersIterator
;
class
BoostCampaigns
extends
Cli\Controller
implements
Interfaces\CliControllerInterface
{
public
function
help
(
$command
=
null
)
{
$this
->
out
(
'Syntax usage: cli trending <type>'
);
}
public
function
exec
()
{
}
public
function
start
()
{
error_reporting
(
E_ALL
);
ini_set
(
'display_errors'
,
1
);
$offset
=
$this
->
getOpt
(
'offset'
)
??
null
;
$type
=
$this
->
getOpt
(
'type'
)
??
'newsfeed'
;
$ownerGuid
=
$this
->
getOpt
(
'ownerGuid'
)
??
null
;
/** @var Core\Boost\Campaigns\Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Boost\Campaigns\Manager'
);
$iterator
=
(
new
Core\Boost\Campaigns\Iterator
())
->
setOffset
(
$offset
)
->
setState
(
Core\Boost\Campaigns\Campaign
::
CREATED_STATUS
)
->
setOwnerGuid
(
$ownerGuid
)
->
setType
(
$type
);
foreach
(
$iterator
as
$campaign
)
{
try
{
$manager
->
start
(
$campaign
);
}
catch
(
\Exception
$e
)
{
error_log
(
get_class
(
$e
)
.
': '
.
$e
->
getMessage
());
continue
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Core/Boost/Campaigns/Iterator.php
0 → 100644
View file @
5cd99f03
<?php
/**
* @author: eiennohi.
*/
namespace
Minds\Core\Boost\Campaigns
;
use
Minds\Core\Di\Di
;
class
Iterator
implements
\Iterator
{
/** @var Manager */
protected
$manager
;
protected
$limit
=
12
;
protected
$from
=
0
;
protected
$offset
=
null
;
protected
$sort
=
'asc'
;
protected
$type
=
'newsfeed'
;
protected
$ownerGuid
=
null
;
protected
$state
=
null
;
/** @var array */
protected
$list
=
null
;
public
function
__construct
(
$manager
=
null
)
{
$this
->
manager
=
$manager
?:
Di
::
_
()
->
get
(
'Boost\Campaigns\Manager'
);
}
/**
* @param int $limit
* @return Iterator
*/
public
function
setLimit
(
int
$limit
)
{
$this
->
limit
=
$limit
;
return
$this
;
}
/**
* @param int $from
* @return Iterator
*/
public
function
setFrom
(
int
$from
)
{
$this
->
from
=
$from
;
return
$this
;
}
/**
* @return int|null
*/
public
function
getOffset
()
{
return
$this
->
offset
;
}
/**
* @param int|null $offset
* @return Iterator
*/
public
function
setOffset
(
$offset
)
{
$this
->
offset
=
$offset
;
return
$this
;
}
/**
* @param string $sort
* @return Iterator
*/
public
function
setSort
(
string
$sort
)
{
$this
->
sort
=
$sort
;
return
$this
;
}
/**
* @param mixed $type
* @return Iterator
*/
public
function
setType
(
$type
)
{
$this
->
type
=
$type
;
return
$this
;
}
/**
* @param null $ownerGuid
* @return Iterator
*/
public
function
setOwnerGuid
(
$ownerGuid
)
{
$this
->
ownerGuid
=
$ownerGuid
;
return
$this
;
}
/**
* @param mixed $state
* @return Iterator
*/
public
function
setState
(
$state
)
{
$this
->
state
=
$state
;
return
$this
;
}
public
function
getList
()
{
$response
=
$this
->
manager
->
getList
([
'limit'
=>
$this
->
limit
,
'from'
=>
$this
->
from
,
'offset'
=>
$this
->
offset
,
'type'
=>
$this
->
type
,
'owner_guid'
=>
$this
->
ownerGuid
,
'state'
=>
$this
->
state
,
]);
$this
->
offset
=
$response
->
getPagingToken
();
$this
->
list
=
$response
;
}
public
function
current
()
{
return
current
(
$this
->
list
);
}
public
function
next
()
{
next
(
$this
->
list
);
}
public
function
key
()
{
return
key
(
$this
->
list
);
}
public
function
valid
()
{
if
(
!
$this
->
list
)
{
return
false
;
}
return
key
(
$this
->
list
)
!==
null
;
}
public
function
rewind
()
{
if
(
$this
->
list
)
{
reset
(
$this
->
list
);
}
$this
->
getList
();
}
}
This diff is collapsed.
Click to expand it.
Core/Boost/Campaigns/Manager.php
View file @
5cd99f03
...
...
@@ -13,10 +13,10 @@ use Minds\Entities\User;
class
Manager
{
/** @var Repository
*/
/** @var Repository */
protected
$repository
;
/** @var ElasticRepository
*/
/** @var ElasticRepository */
protected
$elasticRepository
;
/** @var Delegates\CampaignUrnDelegate */
...
...
@@ -387,19 +387,23 @@ class Manager
throw
new
CampaignException
(
'Campaign should be in [approved] state in order to complete it'
);
}
//
Update
//
Check for completion
$campaign
->
setCompletedTimestamp
(
time
()
*
1000
);
if
(
time
()
*
1000
>=
$campaign
->
getEnd
()
||
$campaign
->
getImpressionsMet
()
>=
$campaign
->
getImpressions
())
{
// Update
// Write
$campaign
->
setCompletedTimestamp
(
time
()
*
1000
);
$this
->
repository
->
update
(
$campaign
);
$this
->
elasticRepository
->
update
(
$campaign
);
// Write
// Budget update
$this
->
repository
->
update
(
$campaign
);
$this
->
elasticRepository
->
update
(
$campaign
);
$this
->
budgetDelegate
->
onStateChange
(
$campaign
);
// Budget update
$this
->
budgetDelegate
->
onStateChange
(
$campaign
);
}
return
$campaign
;
}
...
...
This diff is collapsed.
Click to expand it.
Core/Queue/Runners/BoostCampaignChecker.php
0 → 100644
View file @
5cd99f03
<?php
namespace
Minds\Core\Queue\Runners
;
use
Minds\Core\Boost\Campaigns\Manager
;
use
Minds\Core\Queue
;
use
Minds\Core\Queue\Interfaces
;
use
Minds\Core\Di\Di
;
class
BoostCampaignChecker
implements
Interfaces\QueueRunner
{
public
function
run
()
{
$client
=
Queue\Client
::
Build
();
$client
->
setQueue
(
"BoostCampaignChecker"
)
->
receive
(
function
(
$msg
)
{
$data
=
$msg
->
getData
();
$campaignRef
=
$data
[
'campaignRef'
];
echo
"Checking boost campaign
{
$campaignRef
->
getUrn
()
}
\n
"
;
/** @var Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Boost\Campaigns\Manager'
);
$manager
->
complete
(
$campaignRef
);
});
}
}
This diff is collapsed.
Click to expand it.
containers/php-runners/minds.conf
View file @
5cd99f03
...
...
@@ -157,3 +157,13 @@ numprocs=4
redirect_stderr
=
true
stdout_logfile
=/
dev
/
stdout
stdout_logfile_maxbytes
=
0
[
program
:
minds
-
boost
-
campaing
-
checker
]
process_name
=%(
program_name
)
s_
%(
process_num
)
02
d
command
=
php
/
var
/
www
/
Minds
/
engine
/
cli
.
php
QueueRunner
run
--
runner
=
BoostCampaignChecker
autostart
=
true
autorestart
=
true
numprocs
=
2
redirect_stderr
=
true
stdout_logfile
=/
dev
/
stdout
stdout_logfile_maxbytes
=
0
This diff is collapsed.
Click to expand it.