1. 创建一个类Test来执行Cron Job
    1. <?php
    2. /**
    3. * Tony_SampleMinimal Module Of Magento 2
    4. * Author: Tony
    5. * Home : www.abmbio.xin
    6. */
    7. namespace Tony\SampleMinimal\Cron;
    8. use \Psr\Log\LoggerInterface;
    9. class Test {
    10. protected $logger;
    11. public function __construct(LoggerInterface $logger) {
    12. $this->logger = $logger;
    13. }
    14. /**
    15. * Write to system.log
    16. *
    17. * @return void
    18. */
    19. public function execute() {
    20. $this->logger->info('Cron Works');
    21. }
    22. }
    1. 创建crontab.xml来配置Cron Job
    1. <?xml version="1.0"?>
    2. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
    3. <group id="default">
    4. <job name="custom_cronjob" instance="Tony\SampleMinimal\Cron\Test" method="execute">
    5. <schedule>* * * * *</schedule>
    6. </job>
    7. </group>
    8. </config>
    1. 启用Cron Job
    1. php bin/magento cron:run

    详情请看:Tony Blog