We can run model/observer function using cron as below in magento 1:
<crontab>
<jobs>
<CronCheck>
<schedule>
<cron_expr>*/15 * * * *</cron_expr>
</schedule>
<run>
<model>khaosconnect/Observer::checkCronJobs</model>
</run>
</CronCheck>
</jobs>
</crontab>
so checkCronJobs
function executed according to scheduled cron job.
In magento2 how we can run the specific class function using cron? As we have use below in magento 2 :
<?php
namespace Company\Module\Cron;
class Runcronjobs
{
protected $_logger;
public function __construct(
\Psr\Log\LoggerInterface $logger
)
{
$this->_logger = $logger;
}
public function execute()
{
//Edit it according to your requirement
$this->_logger->debug('Cron run successfully');
return $this;
}
}
In magento 2 I have checkCronJobs
function in namespace Company\Module\Model
class;
Is there any other way to call function in cron or we need to pass checkCronJobs
with all dependencies in Runcronjobs.php
file as we do normally in M2.