Create a new module with Bluethink_Cronjob
Please follow the guides to start the cron job program as your wish:
Step 1: Create registration.php file.
app/code/Bluethink/Cronjob/registration.php
1 2 3 4 5 6 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Bluethink_Cronjob', __DIR__ ); |
Step 2: Create module.xml file.
app/code/Bluethink/Cronjob/etc/module.xml
1 2 3 4 5 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Bluethink_Cronjob" setup_version="1.0.0"> </module> </config> |
Step 3: Create Test.php file.
app/code/Bluethink/Cronjob/Cron/Test.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php namespace Bluethink\Cronjob\Cron; use \Psr\Log\LoggerInterface; class Test { protected $logger; public function __construct(LoggerInterface $logger) { $this->logger = $logger; } /** * Write to system.log * * @return void */ public function execute() { // Do your Stuff $this->logger->info('Cron Works'); } } |
Step 4: Create crontab.xml file
app/code/Bluethink/Cronjob/etc/crontab.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd"> <group id="default"> <job name="custom_cronjob" instance="Bluethink\Crontab\Cron\Test" method="execute"> <schedule>* * * * *</schedule> </job> </group> </config> |
bluethinkinc_blog
2022-09-30