Magento

[Magento] magento 2 Run cron

chsr 2023. 3. 23. 10:50
728x90
반응형

■ Magento 2 Run cron 

필요 시 크론 강제로 돌려볼때 사용할 수 있음


 terminal or iterm group cron 돌리기

*특정 group cron 돌릴경우 default 아닌 group id 변경해주면  

php bin/magento cron:run --group default

 특정 페이지 호출 cron 돌려보고 싶은 경우

$cron = \Magento\Framework\App\ObjectManager::getInstance()
                    ->create('Vendor\Module\Cron\Test');

$cron->execute();

 예시

**Note if using Nginx you can put these files in the pub/ folder and adjust the require path for the Test.php file to require '../app/bootstrap.php';

  • Test.php
<?php
    require __DIR__ . '/app/bootstrap.php';
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
    /** @var \Magento\Framework\App\Http $app */
    $app = $bootstrap->createApplication('TestApp');
    $bootstrap->run($app);
  • TestApp.php
public function launch()
 {
        /** @var \Vendor\Module\Cron\Test $cron */
        $cron = \Magento\Framework\App\ObjectManager::getInstance()
            ->create('Vendor\Module\Cron\Test');

        $cron->execute();

        return $this->_response;

 }

 

참고

 

Magento 2 run a specific Cron without cron:run CLI command?

To make a long story short xdebug will not reliably stop on the breakpoints in my cron files when using the typical: php bin/magento cron:run Xdebug is all setup properly and sometimes it will wo...

magento.stackexchange.com

 

728x90
반응형