More try-catch. Logs added.
This commit is contained in:
parent
5b63cac5ec
commit
b76036573a
|
@ -2,12 +2,13 @@
|
||||||
|
|
||||||
namespace Skobkin\Bundle\PointToolsBundle\Command;
|
namespace Skobkin\Bundle\PointToolsBundle\Command;
|
||||||
|
|
||||||
|
|
||||||
use Skobkin\Bundle\PointToolsBundle\Service\SubscriptionsManager;
|
use Skobkin\Bundle\PointToolsBundle\Service\SubscriptionsManager;
|
||||||
use Skobkin\Bundle\PointToolsBundle\Service\UserApi;
|
use Skobkin\Bundle\PointToolsBundle\Service\UserApi;
|
||||||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
||||||
|
use Symfony\Component\Console\Input\Input;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\Output;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
||||||
|
@ -27,8 +28,17 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Input $input
|
||||||
|
* @param Output $output
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
|
$log = $this->getContainer()->get('logger');
|
||||||
|
|
||||||
|
$log->info('UpdateSubscriptionsCommand started.');
|
||||||
|
|
||||||
/** @var UserApi $api */
|
/** @var UserApi $api */
|
||||||
$api = $this->getContainer()->get('skobkin_point_tools.api_user');
|
$api = $this->getContainer()->get('skobkin_point_tools.api_user');
|
||||||
/** @var SubscriptionsManager $subscriptionsManager */
|
/** @var SubscriptionsManager $subscriptionsManager */
|
||||||
|
@ -38,7 +48,9 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
||||||
$serviceUser = $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('SkobkinPointToolsBundle:User')->findOneBy(['login' => $serviceUserName]);
|
$serviceUser = $this->getContainer()->get('doctrine.orm.entity_manager')->getRepository('SkobkinPointToolsBundle:User')->findOneBy(['login' => $serviceUserName]);
|
||||||
|
|
||||||
if (!$serviceUser) {
|
if (!$serviceUser) {
|
||||||
|
$log->info('Service user not found');
|
||||||
// @todo Retrieving user
|
// @todo Retrieving user
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +61,13 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
||||||
try {
|
try {
|
||||||
$serviceSubscribers = $api->getUserSubscribersByLogin($serviceUserName);
|
$serviceSubscribers = $api->getUserSubscribersByLogin($serviceUserName);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
// @todo fallback to the local subscribers list
|
||||||
$output->writeln('Error while getting service subscribers');
|
$output->writeln('Error while getting service subscribers');
|
||||||
|
$log->error('Error while getting service subscribers.' . PHP_EOL .
|
||||||
|
$e->getMessage() . PHP_EOL .
|
||||||
|
$e->getFile() . ':' . $e->getLine()
|
||||||
|
);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +76,16 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updating service subscribers
|
// Updating service subscribers
|
||||||
|
try {
|
||||||
$subscriptionsManager->updateUserSubscribers($serviceUser, $serviceSubscribers);
|
$subscriptionsManager->updateUserSubscribers($serviceUser, $serviceSubscribers);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$log->error('Error while updating service subscribers' . PHP_EOL .
|
||||||
|
$e->getMessage() . PHP_EOL .
|
||||||
|
$e->getFile() . ':' . $e->getLine()
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($output->isVerbose()) {
|
if ($output->isVerbose()) {
|
||||||
$output->writeln('Processing service subscribers');
|
$output->writeln('Processing service subscribers');
|
||||||
|
@ -67,19 +94,33 @@ class UpdateSubscriptionsCommand extends ContainerAwareCommand
|
||||||
// Updating service users subscribers
|
// Updating service users subscribers
|
||||||
foreach ($serviceSubscribers as $user) {
|
foreach ($serviceSubscribers as $user) {
|
||||||
$output->writeln(' Processing @' . $user->getLogin());
|
$output->writeln(' Processing @' . $user->getLogin());
|
||||||
|
$log->info('Processing @' . $user->getLogin());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$userCurrentSubscribers = $api->getUserSubscribersByLogin($user->getLogin());
|
$userCurrentSubscribers = $api->getUserSubscribersByLogin($user->getLogin());
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$output->writeln(' Error while getting subscribers. Skipping.');
|
$output->writeln(' Error while getting subscribers. Skipping.');
|
||||||
|
$log->error('Error while getting subscribers.' . PHP_EOL .
|
||||||
|
$e->getMessage() . PHP_EOL .
|
||||||
|
$e->getFile() . ':' . $e->getLine()
|
||||||
|
);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($output->isVerbose()) {
|
if ($output->isVerbose()) {
|
||||||
$output->writeln(' Updating service subscribers');
|
$output->writeln(' Updating user subscribers');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Updating user subscribers
|
||||||
$subscriptionsManager->updateUserSubscribers($user, $userCurrentSubscribers);
|
$subscriptionsManager->updateUserSubscribers($user, $userCurrentSubscribers);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$log->error('Error while updating user subscribers' . PHP_EOL .
|
||||||
|
$e->getMessage() . PHP_EOL .
|
||||||
|
$e->getFile() . ':' . $e->getLine()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// @todo some pause for lower API load
|
// @todo some pause for lower API load
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,6 @@ class SubscriptionsManager
|
||||||
->andWhere('s.subscriber IN (:subscribers)')
|
->andWhere('s.subscriber IN (:subscribers)')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
/** @var User $unsubscribedUser */
|
/** @var User $unsubscribedUser */
|
||||||
foreach ($unsubscribedList as $unsubscribedUser) {
|
foreach ($unsubscribedList as $unsubscribedUser) {
|
||||||
$logEvent = new SubscriptionEvent();
|
$logEvent = new SubscriptionEvent();
|
||||||
|
|
Loading…
Reference in a new issue