Skip to content

Commit

Permalink
Added options
Browse files Browse the repository at this point in the history
  • Loading branch information
heathdutton committed May 15, 2018
1 parent 71e9c51 commit 45b5bbe
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 23 deletions.
57 changes: 40 additions & 17 deletions Command/HealthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Mautic\CoreBundle\Command\ModeratedCommand;
use MauticPlugin\MauticHealthBundle\Model\HealthModel;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -29,7 +30,21 @@ class HealthCommand extends ModeratedCommand
protected function configure()
{
$this->setName('mautic:health:check')
->setDescription('General all purpose health check.');
->setDescription('General all purpose health check.')
->addOption(
'campaign-rebuild-threshold',
null,
InputOption::VALUE_OPTIONAL,
'The maximum number of contacts waiting to be ingested into a campaign from a segment.',
10000
)
->addOption(
'campaign-trigger-threshold',
null,
InputOption::VALUE_OPTIONAL,
'The maximum number of contacts waiting for scheduled campaign events to fire which are late.',
1000
);

parent::configure();
}
Expand All @@ -42,28 +57,36 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getContainer();
$translator = $container->get('translator');
$verbose = $input->getOption('verbose');
$campaignRebuildThreshold = $input->getOption('campaign-rebuild-threshold');
$campaignTriggerThreshold = $input->getOption('campaign-trigger-threshold');
$container = $this->getContainer();
$translator = $container->get('translator');

if (!$this->checkRunStatus($input, $output)) {
return 0;
}

/** @var HealthModel $healthModel */
$healthModel = $container->get('mautic.health.model.health');
$output->writeln(
'<info>'.$translator->trans(
'mautic.health.running'
).'</info>'
);
$healthModel->campaignRebuildCheck($output);
$healthModel->campaignTriggerCheck($output);
$healthModel->getIncidents($output);
$output->writeln(
'<info>'.$translator->trans(
'mautic.health.complete'
).'</info>'
);

if ($verbose) {
$output->writeln(
'<info>'.$translator->trans(
'mautic.health.running'
).'</info>'
);
}
$healthModel->setCampaignRebuildThreshold($campaignRebuildThreshold);
$healthModel->setCampaignTriggerThreshold($campaignTriggerThreshold);
$healthModel->campaignRebuildCheck($output, $verbose);
$healthModel->campaignTriggerCheck($output, $verbose);
if ($verbose) {
$output->writeln(
'<info>'.$translator->trans(
'mautic.health.complete'
).'</info>'
);
}
$this->completeRun();

return 0;
Expand Down
45 changes: 39 additions & 6 deletions Model/HealthModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace MauticPlugin\MauticHealthBundle\Model;

use Doctrine\ORM\EntityManager;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class HealthModel.
Expand All @@ -25,10 +26,10 @@ class HealthModel
protected $campaigns;

/** @var int */
protected $campaignRebuildThreshold = 10000;
protected $campaignRebuildThreshold;

/** @var int */
protected $campaignTriggerThreshold = 1000;
protected $campaignTriggerThreshold;

/** @var array */
protected $incidents;
Expand All @@ -44,13 +45,38 @@ public function __construct(
$this->em = $em;
}

/**
* @param $campaignRebuildThreshold
*
* @return $this
*/
public function setCampaignRebuildThreshold($campaignRebuildThreshold)
{
$this->campaignRebuildThreshold = $campaignRebuildThreshold;

return $this;
}

/**
* @param $campaignTriggerThreshold
*
* @return $this
*/
public function setCampaignTriggerThreshold($campaignTriggerThreshold)
{
$this->campaignTriggerThreshold = $campaignTriggerThreshold;

return $this;
}

/**
* Discern the number of leads waiting on mautic:campaign:rebuild.
* This typically means a large segment has been given a campaign.
*
* @param null $output
* @param OutputInterface $output
* @param bool $verbose
*/
public function campaignRebuildCheck($output = null)
public function campaignRebuildCheck(OutputInterface $output = null, $verbose = false)
{
$query = $this->em->getConnection()->createQueryBuilder();
$query->select('cl.campaign_id as campaign_id, count(DISTINCT(cl.lead_id)) as contact_count');
Expand All @@ -76,6 +102,9 @@ public function campaignRebuildCheck($output = null)
$status = 'error';
} else {
$status = 'info';
if (!$verbose) {
continue;
}
}
$output->writeln(
'<'.$status.'>'.
Expand All @@ -90,9 +119,10 @@ public function campaignRebuildCheck($output = null)
* Discern the number of leads waiting on mautic:campaign:trigger.
* This will happen if it takes longer to execute triggers than for new contacts to be consumed.
*
* @param null $output
* @param OutputInterface $output
* @param bool $verbose
*/
public function campaignTriggerCheck($output = null)
public function campaignTriggerCheck(OutputInterface $output = null, $verbose = false)
{
$query = $this->em->getConnection()->createQueryBuilder();
$query->select('el.campaign_id as campaign_id, COUNT(DISTINCT(el.lead_id)) as contact_count');
Expand All @@ -116,6 +146,9 @@ public function campaignTriggerCheck($output = null)
$status = 'error';
} else {
$status = 'info';
if (!$verbose) {
continue;
}
}
$output->writeln(
'<'.$status.'>'.
Expand Down

0 comments on commit 45b5bbe

Please sign in to comment.