How to override cron job group in Magento 2?

You can see your existing cron Group name from your module crontab.xml file.

Override the Module Cron Job group from default to custom group easily. Also, you can change the cron schedule time.

If you want to override any existing Crom Job that contains a default Group, You can change it to your custom group by creating a simple module. Continue reading “How to override cron job group in Magento 2?”

How to reindex indexer programmatically in magento 2?

Just create PHP file under your module’s Cron folder,
A created module like Rbj_Indexing for reference, Create Indexer.php file and call execute() function,

<?php
namespace Rbj\Indexing\Cron;

class Indexer
{
    public function __construct(
        \Magento\Indexer\Model\Processor $processor
    ) {
        $this->processor = $processor;
    }

    public function execute()
    {
        /* Regenerate indexes for all indexers */
        $this->processor->reindexAll();

        /* Regenerate indexes for all invalid indexers */
        $this->processor->reindexAllInvalid()
    }
}

There are two types of method for indexing.

1. Regenerate indexes for all indexers
$this->processor->reindexAll();

2. Regenerate indexes for all invalid indexers. This will only regenerate for invalid indexer.
$this->processor->reindexAllInvalid()