Skip to content

Commit

Permalink
Rewrite Package discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
flavioheleno committed Apr 20, 2022
1 parent 8a98514 commit b1ee0c9
Show file tree
Hide file tree
Showing 26 changed files with 333 additions and 301 deletions.
5 changes: 0 additions & 5 deletions app/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@

/* PACKAGE EVENTS */
$router
->addRoute(
PackageCreatedEvent::class,
PackageCreatedListener::class,
'PackageCreated'
)
->addRoute(
PackageUpdatedEvent::class,
PackageUpdatedListener::class,
Expand Down
2 changes: 0 additions & 2 deletions app/processors.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Application\Processor\Handler\UpdateDependencyStatusHandler;
use App\Application\Processor\Handler\UpdateVersionStatusHandler;
use App\Application\Processor\Listener\Dependency\DependencyUpdatedListener;
use App\Application\Processor\Listener\Package\PackageCreatedListener;
use App\Application\Processor\Listener\Package\PackageUpdatedListener;
use App\Application\Processor\Listener\Version\VersionCreatedListener;
use DI\ContainerBuilder;
Expand All @@ -25,7 +24,6 @@
$containerBuilder->addDefinitions(
[
DependencyUpdatedListener::class => autowire(DependencyUpdatedListener::class),
PackageCreatedListener::class => autowire(PackageCreatedListener::class),
PackageUpdatedListener::class => autowire(PackageUpdatedListener::class),
VersionCreatedListener::class => autowire(VersionCreatedListener::class),
]
Expand Down
20 changes: 9 additions & 11 deletions src/Application/Console/Packagist/GetDataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,17 +410,15 @@ static function (string $key): bool {
)
);
} catch (Exception $exception) {
if (isset($io) === true) {
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}

return Command::FAILURE;
Expand Down
91 changes: 33 additions & 58 deletions src/Application/Console/Packagist/GetListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
namespace App\Application\Console\Packagist;

use App\Application\Message\Command\PackageDiscoveryCommand;
use App\Application\Message\Event\Package\PackageCreatedEvent;
use App\Application\Message\Event\Package\PackageRemovedEvent;
use App\Domain\Package\Package;
use App\Domain\Package\PackageRepositoryInterface;
use App\Application\Service\Packagist;
Expand Down Expand Up @@ -41,10 +39,10 @@ protected function configure(): void {
$this
->setDescription('Get the complete list of packages from a Packagist mirror')
->addOption(
'resync',
'r',
'offline',
null,
InputOption::VALUE_NONE,
'Resync the list'
'Work in offline mode'
)
->addOption(
'mirror',
Expand Down Expand Up @@ -75,6 +73,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);

$workOffline = (bool)$input->getOption('offline');

if ($workOffline) {
$io->text(
sprintf(
'[%s] Running in <options=bold;fg=red>offline</> mode',
date('H:i:s')
)
);

$this->packagist->setOffline();
}

$mirror = $input->getOption('mirror');
if (filter_var($mirror, FILTER_VALIDATE_URL) === false) {
throw new InvalidArgumentException('Invalid mirror option');
Expand All @@ -97,36 +108,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);

if ((bool)$input->getOption('resync')) {
$io->text(
sprintf(
'[%s] Running in resync mode',
date('H:i:s')
)
);

foreach ($packageList as $package) {
if ($this->packageRepository->exists($package)) {
$package = $this->packageRepository->get($package);
} else {
$package = $this->packageRepository->create($package);
}

$this->producer->sendCommand(
new PackageDiscoveryCommand($package)
);
}

$io->text(
sprintf(
'[%s] Done',
date('H:i:s')
)
);

return Command::SUCCESS;
}

$packageCol = $this->packageRepository->all();
$packages = $packageCol->map(
static function (Package $package): string {
Expand Down Expand Up @@ -162,13 +143,13 @@ static function (Package $package): string {
)
);

$removeList = array_diff($packages, $packageList);
$remList = array_diff($packages, $packageList);
$io->text(
sprintf(
'[%s] <options=bold;fg=red>%s</> package(s) will be removed',
date('H:i:s'),
number_format(
count($removeList),
count($remList),
0,
',',
'.'
Expand All @@ -177,10 +158,8 @@ static function (Package $package): string {
);

foreach ($addList as $packageName) {
$package = $this->packageRepository->create($packageName);

$this->producer->sendEvent(
new PackageCreatedEvent($package)
$this->producer->sendCommand(
new PackageDiscoveryCommand($packageName, workOffline: $workOffline)
);

if ($this->mustStop === true) {
Expand All @@ -195,13 +174,11 @@ static function (Package $package): string {
}
}

foreach ($removeList as $packageName) {
// $this->packageRepository->delete($package);
//
// $this->producer->sendEvent(
// new PackageRemovedEvent($package)
foreach ($remList as $packageName) {
// $this->producer->sendCommand(
// new PackageRemovalCommand($packageName)
// );
//

// if ($this->mustStop === true) {
// $io->text(
// sprintf(
Expand All @@ -221,17 +198,15 @@ static function (Package $package): string {
)
);
} catch (Exception $exception) {
if (isset($io) === true) {
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}

return Command::FAILURE;
Expand Down
20 changes: 9 additions & 11 deletions src/Application/Console/Packagist/GetUpdatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);
} catch (Exception $exception) {
if (isset($io) === true) {
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}

return Command::FAILURE;
Expand Down
22 changes: 10 additions & 12 deletions src/Application/Console/Packagist/MassImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);
} catch (Exception $exception) {
if (isset($io) === true) {
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}

return Command::FAILURE;
Expand All @@ -146,7 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

public function __construct(PackageRepositoryInterface $packageRepository) {
$this->packageRepository = $packageRepository;
$this->packageRepository = $packageRepository;

parent::__construct();
}
Expand Down
28 changes: 12 additions & 16 deletions src/Application/Console/Queue/ConsumeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function configure(): void {
1
)
->addArgument(
'name',
'queueName',
InputArgument::REQUIRED,
'Name of the bus queue'
);
Expand Down Expand Up @@ -73,7 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$messageCount = (int)$input->getOption('messageCount');

$queueName = $input->getArgument('name');
$queueName = $input->getArgument('queueName');

if ($output->isVerbose()) {
$io->text(
Expand Down Expand Up @@ -124,17 +124,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
)
);
} catch (Exception $exception) {
if (isset($io) === true) {
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}

return Command::FAILURE;
Expand All @@ -143,9 +141,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::SUCCESS;
}

public function __construct(
Consumer $consumer
) {
public function __construct(Consumer $consumer) {
$this->consumer = $consumer;

parent::__construct();
Expand Down
24 changes: 10 additions & 14 deletions src/Application/Console/Queue/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$table->render();
} catch (Exception $exception) {
if (isset($io) === true) {
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}
$io->error(
sprintf(
'[%s] %s',
date('H:i:s'),
$exception->getMessage()
)
);
if ($output->isDebug()) {
$io->listing(explode(PHP_EOL, $exception->getTraceAsString()));
}

return Command::FAILURE;
Expand All @@ -89,9 +87,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::SUCCESS;
}

public function __construct(
Bus $bus
) {
public function __construct(Bus $bus) {
$this->bus = $bus;

parent::__construct();
Expand Down
Loading

0 comments on commit b1ee0c9

Please sign in to comment.