Skip to content

Commit 0415eb2

Browse files
committed
MAGE-938 Switch to crontab area for less resource usage
1 parent 3be9d74 commit 0415eb2

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

Console/Command/ReplicaDeleteCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ protected function configure(): void
6060

6161
protected function execute(InputInterface $input, OutputInterface $output): int
6262
{
63+
$this->output = $output;
64+
$this->input = $input;
65+
6366
$storeIds = (array) $input->getArgument(self::STORE_ARGUMENT);
6467
$unused = $input->getOption(self::UNUSED_OPTION);
6568

@@ -70,8 +73,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7073
$output->writeln("<info>$msg</info>");
7174
}
7275

73-
$this->output = $output;
74-
$this->input = $input;
7576

7677
if ($unused) {
7778
$unusedReplicas = $this->getUnusedReplicas($storeIds);

Console/Command/ReplicaSyncCommand.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ class ReplicaSyncCommand extends Command
2626

2727
protected ?OutputInterface $output = null;
2828

29-
/**
30-
* @param ProductHelper $productHelper
31-
* @param ReplicaManagerInterface $replicaManager
32-
* @param StoreManagerInterface $storeManager
33-
* @param string|null $name
34-
*/
3529
public function __construct(
3630
protected State $state,
3731
protected ProductHelper $productHelper,
@@ -74,6 +68,9 @@ protected function configure(): void
7468
*/
7569
protected function execute(InputInterface $input, OutputInterface $output): int
7670
{
71+
$this->output = $output;
72+
$this->setAreaCode();
73+
7774
$storeIds = (array) $input->getArgument(self::STORE_ARGUMENT);
7875

7976
$msg = 'Syncing replicas for ' . ($storeIds ? count($storeIds) : 'all') . ' store' . (!$storeIds || count($storeIds) > 1 ? 's' : '');
@@ -83,11 +80,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8380
$output->writeln("<info>$msg</info>");
8481
}
8582

86-
$this->output = $output;
87-
$this->state->setAreaCode(Area::AREA_ADMINHTML);
83+
8884
try {
8985
$this->syncReplicas($storeIds);
90-
} catch (BadRequestException $e) {
86+
} catch (BadRequestException) {
9187
$this->output->writeln('<comment>You appear to have a corrupted replica configuration in Algolia for your Magento instance.</comment>');
9288
$this->output->writeln('<comment>Run the "algolia:replicas:rebuild" command to correct this.</comment>');
9389
return CLI::RETURN_FAILURE;
@@ -100,6 +96,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
10096
return Cli::RETURN_SUCCESS;
10197
}
10298

99+
protected function setAreaCode(): void {
100+
try {
101+
$this->state->setAreaCode(Area::AREA_CRONTAB);
102+
} catch (LocalizedException) {
103+
// Area code is already set - nothing to do
104+
}
105+
}
106+
103107
/**
104108
* @param int[] $storeIds
105109
* @return void

0 commit comments

Comments
 (0)