I have created a custom module and created the cron in magento 2.2.6
crontab.xml Learning\GreetingMessage\etc\crontab.xml
<?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="index">
<job name="samplecron" instance="Learning\GreetingMessage\Cron\Test" method="execute">
<schedule>*/1 * * * *</schedule>
</job>
</group>
</config>
Test.php Learning\GreetingMessage\Cron\Test.php
<?php
namespace Learning\GreetingMessage\Cron;
class Test {
protected $_logger;
protected $_test;
public function __construct(
\Psr\Log\LoggerInterface $logger,
**\Learning\GreetingMessage\Controller\Index\Text $text**
) {
$this->_logger = $logger;
$this->_test = $test;
}
/**
* Method executed when cron runs in server
*/
public function execute() {
**$this->_test->execute();**
$this->_logger->debug('Running Cron from Test class');
return $this;
}
}
I have controller in Learning\GreetingMessage\Controller\Index\Text.php
It is not working . it says Class Learning\GreetingMessage\Controller\Index\Text does not exist
message in cron_schedule table