Commit 09997460 authored by Emiliano Balbuena's avatar Emiliano Balbuena

(fix): Synchronous queue save; update impression on revoke

1 merge request!235WIP: Boost Campaigns (&24)
Pipeline #73585750 running with stages
......@@ -23,6 +23,9 @@ class Manager
/** @var ElasticRepository */
protected $elasticRepository;
/** @var Metrics */
protected $metrics;
/** @var PaymentsRepository */
protected $paymentsRepository;
......@@ -51,8 +54,9 @@ class Manager
* Manager constructor.
* @param Repository $repository
* @param ElasticRepository $elasticRepository
* @param Metrics $metrics
* @param PaymentsRepository $paymentsRepository
* @param null $queueClient
* @param QueueClientInterface $queueClient
* @param Delegates\CampaignUrnDelegate $campaignUrnDelegate
* @param Delegates\NormalizeDatesDelegate $normalizeDatesDelegate
* @param Delegates\NormalizeEntityUrnsDelegate $normalizeEntityUrnsDelegate
......@@ -63,6 +67,7 @@ class Manager
public function __construct(
$repository = null,
$elasticRepository = null,
$metrics = null,
$paymentsRepository = null,
$queueClient = null,
$campaignUrnDelegate = null,
......@@ -74,6 +79,7 @@ class Manager
{
$this->repository = $repository ?: new Repository();
$this->elasticRepository = $elasticRepository ?: new ElasticRepository();
$this->metrics = $metrics ?: new Metrics();
$this->paymentsRepository = $paymentsRepository ?: new PaymentsRepository();
$this->queueClient = $queueClient ?: QueueClient::build();
......@@ -99,6 +105,7 @@ class Manager
/**
* @param array $opts
* @return Response
* @throws Exception
*/
public function getList(array $opts = [])
{
......@@ -146,6 +153,7 @@ class Manager
/**
* @param $urn
* @param array $opts
* @return Campaign|null
* @throws Exception
*/
......@@ -241,6 +249,7 @@ class Manager
* @param mixed $paymentPayload
* @return Campaign
* @throws CampaignException
* @throws Exception
*/
public function update(Campaign $campaignRef, $paymentPayload = null)
{
......@@ -286,8 +295,7 @@ class Manager
// Write
$this->repository->update($campaign);
$this->elasticRepository->update($campaign);
$this->sync($campaign);
// Queue for lifecycle events
......@@ -309,7 +317,7 @@ class Manager
*/
public function sync(Campaign $campaign)
{
$this->repository->update($campaign);
$this->repository->update($campaign, true);
$this->elasticRepository->update($campaign);
return $campaign;
......@@ -362,8 +370,7 @@ class Manager
// Write
$this->repository->update($campaign);
$this->elasticRepository->update($campaign);
$this->sync($campaign);
//
......@@ -398,6 +405,12 @@ class Manager
throw new CampaignException('Campaign should be in [created] or [approved] state in order to cancel it');
}
// Sync impressions
$campaign = $this->metrics
->setCampaign($campaign)
->syncImpressionsMet();
// Update
$campaign
......@@ -409,8 +422,7 @@ class Manager
// Write
$this->repository->update($campaign);
$this->elasticRepository->update($campaign);
$this->sync($campaign);
//
......@@ -454,8 +466,7 @@ class Manager
// Write
$this->repository->update($campaign);
$this->elasticRepository->update($campaign);
$this->sync($campaign);
//
......@@ -499,8 +510,7 @@ class Manager
// Write
$this->repository->update($campaign);
$this->elasticRepository->update($campaign);
$this->sync($campaign);
return $campaign;
}
......
......@@ -99,7 +99,7 @@ class Repository
->setImpressionsMet($data['impressions_met'])
->setRating($data['rating'])
->setQuality($data['quality'])
->setCreatedTimestamp(((int) $data['timestamp_timestamp']) ?: null)
->setCreatedTimestamp(((int) $data['created_timestamp']) ?: null)
->setReviewedTimestamp(((int) $data['reviewed_timestamp']) ?: null)
->setRejectedTimestamp(((int) $data['rejected_timestamp']) ?: null)
->setRevokedTimestamp(((int) $data['revoked_timestamp']) ?: null)
......@@ -120,10 +120,10 @@ class Repository
/**
* @param Campaign $campaign
* @param bool $async
* @return bool
* @throws Exception
*/
public function add(Campaign $campaign)
public function add(Campaign $campaign, $async = true)
{
$cql = "INSERT INTO boost_campaigns (type, guid, owner_guid, json_data, delivery_status) VALUES (?, ?, ?, ?, ?)";
$values = [
......@@ -159,17 +159,17 @@ class Repository
$prepared = new Custom();
$prepared->query($cql, $values);
return (bool) $this->db->request($prepared, true);
return (bool) $this->db->request($prepared, $async);
}
/**
* @param Campaign $campaign
* @param bool $async
* @return bool
* @throws Exception
*/
public function update(Campaign $campaign)
public function update(Campaign $campaign, $async = true)
{
return $this->add($campaign);
return $this->add($campaign, $async);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment