0

Here Data Was Successfully Addded Into Database When i Run php bin\magento cron:run Command But AutoMatically Data Wasn't Added.

vendor\module_name\Cron\Test.php

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() {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // Instance of object manager
        $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
        $connection = $resource->getConnection();
        $tableName = $resource->getTableName('my_employee');
        $sql = "Insert Into " . $tableName . " (name, position,status) Values ('Cron','CronTesting','0')";
        $connection->query($sql);
    }
}

vendor\module_name\etc\frontend\crontab.xml

<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="Vendor\Module_name\Cron\Test" method="execute">
            <schedule>* * * * *</schedule>
        </job>
    </group>
</config>

vendor\module_name\etc\frontend\cron_groups.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/cron_groups.xsd">
    <group id="custom_crongroup">
        <schedule_generate_every>1</schedule_generate_every>
        <schedule_ahead_for>4</schedule_ahead_for>
        <schedule_lifetime>2</schedule_lifetime>
        <history_cleanup_every>10</history_cleanup_every>
        <history_success_lifetime>60</history_success_lifetime>
        <history_failure_lifetime>600</history_failure_lifetime>
        <use_separate_process>1</use_separate_process>
    </group>
</config>
0

Change cron_tab and cron_groups file path :-

vendor\module_name\etc\crontab.xml

vendor\module_name\etc\cron_groups.xml

  • Where I add this Files Can you Provide me a Path ? – user82717 Sep 5 '19 at 10:51
  • just move this file into etc folder – Rk Rathod Sep 5 '19 at 10:52
  • Still It is Not Working ! – user82717 Sep 5 '19 at 10:55
  • clean cache and try – Rk Rathod Sep 5 '19 at 10:55
  • drive.google.com/file/d/13Ng-LAnvZ8u_VSMOutE1bvQyHESrcCsn/… It is Displayed in the Backend – user82717 Sep 5 '19 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy