Skip to content

Commit

Permalink
Skipping stock deploy, adding new command.
Browse files Browse the repository at this point in the history
  • Loading branch information
fooman committed Nov 29, 2017
1 parent 6862632 commit 97735bb
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Magento\NewRelicReporting\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;

use Magento\NewRelicReporting\Model\Apm\DeploymentsFactory;
use Magento\NewRelicReporting\Model\ServiceShellUser;

class DeployMarker extends Command
{
protected $deploymentsFactory;
protected $serviceShellUser;

public function __construct(
DeploymentsFactory $deploymentsFactory,
ServiceShellUser $serviceShellUser,
$name = null
) {
$this->deploymentsFactory = $deploymentsFactory;
$this->serviceShellUser = $serviceShellUser;
parent::__construct($name);
}

protected function configure()
{
$this->setName("newrelic:create:deploy-marker");
$this->setDescription("Check the deploy queue for entries and create an appropriate deploy marker.")
->addArgument(
'message',
InputArgument::REQUIRED,
'Deploy Message?'
)
->addArgument(
'changelog',
InputArgument::REQUIRED,
'Change Log?'
)
->addArgument(
'user',
InputArgument::OPTIONAL,
'Deployment User'
);
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->deploymentsFactory->create()->setDeployment(
$input->getArgument('message'),
$input->getArgument('changelog'),
$this->serviceShellUser->get($input->getArgument('user'))
);
$output->writeln('<info>NewRelic deployment information sent</info>');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ protected function reportCounts()
public function report()
{
if ($this->config->isNewRelicEnabled()) {
$this->reportModules();
$this->reportCounts();
}

Expand Down
22 changes: 22 additions & 0 deletions app/code/Magento/NewRelicReporting/Model/ServiceShellUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Magento\NewRelicReporting\Model;

class ServiceShellUser
{
const DEFAULT_USER = 'cron';

public function get($userFromArgument = false)
{
if ($userFromArgument) {
return $userFromArgument;
}

$user = `echo \$USER`;
if ($user) {
return $user;
}

return self::DEFAULT_USER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,10 @@ public function testReportNewRelicCronModuleDisabledFromConfig()
*/
public function testReportNewRelicCron()
{
$testModuleData = [
'changes' => [
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled'],
],
'enabled' => 1,
'disabled' => 1,
'installed' => 1,
];

$this->config->expects($this->once())
->method('isNewRelicEnabled')
->willReturn(true);
$this->collect->expects($this->once())
->method('getModuleData')
->willReturn($testModuleData);
$this->counter->expects($this->once())
->method('getAllProductsCount');
$this->counter->expects($this->once())
Expand Down Expand Up @@ -198,24 +184,10 @@ public function testReportNewRelicCron()
*/
public function testReportNewRelicCronRequestFailed()
{
$testModuleData = [
'changes' => [
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'],
['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled'],
],
'enabled' => 1,
'disabled' => 1,
'installed' => 1,
];

$this->config->expects($this->once())
->method('isNewRelicEnabled')
->willReturn(true);
$this->collect->expects($this->once())
->method('getModuleData')
->willReturn($testModuleData);
$this->counter->expects($this->once())
->method('getAllProductsCount');
$this->counter->expects($this->once())
Expand Down
8 changes: 8 additions & 0 deletions app/code/Magento/NewRelicReporting/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@
<type name="Magento\Framework\App\Http">
<plugin name="framework-http-newrelic" type="Magento\NewRelicReporting\Plugin\HttpPlugin"/>
</type>
<type name="Magento\Framework\Console\CommandList">
<arguments>
<argument name="commands" xsi:type="array">
<item name="magento_new_relic_reporting_command_deploy_marker"
xsi:type="object">Magento\NewRelicReporting\Console\Command\DeployMarker</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit 97735bb

Please sign in to comment.