1

Our customer uses a tool for importing products. This tool does not trigger reindexing on save.

When I look at the indexing modes of Magento 1.9 indexers I see real_time and manual.

Is there a way to schedule reindexing from Magento or am I ought to use a OS schedule/cron?

1

2 Answers 2

2

Since your questions are mixed up a little let me split them up first of all:

Does the magento 1.9 schedule start reindexing?

Yes - and no. By default, Magento 1.9 (earlier versions most likely as well) will run re-indexing of prices catalog/observer::reindexProductPrices with the cron expression 0 2 * * * (= 2 am in the morning). You may consider installing Aoe_Scheduler (link) to get a better idea on what is running as a scheduled task.

Is there a way to schedule reindexing from Magento or am I ought to use a OS schedule/cron?

Even though running tasks such as re-indexing in a separate cron is widely encouraged I'm not really happy with this approach. At the end there is a reason why Magento has one cron script (ok, two, cron.php and cron.sh but that comes to the same point at the end) to run multiple tasks. Point being, when you more or less force re-indexing by a separate cron job on your server, how can you make sure that for example the import process is done already and/or there is no other scheduled task currently running by the native Magento cron which you usually don't want to conflict with each other? The same basically counts for "external" import scripts. This means, ultimately I would suggest everybody to keep even these processes managed by Magento by a custom extension for example.

One simple approach for running re-indexing in Magento automatically based on a scheduled task is this:

app/etc/modules/Vendorname_Indexer.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Vendorname_Indexer>
            <active>true</active>
            <codePool>local</codePool>
        </Vendorname_Indexer>
    </modules>
</config>

app/code/local/Vendorname/Indexer/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Vendorname_Indexer>
            <version>1.0.0</version>
        </Vendorname_Indexer>
    </modules>
    <global>
        <models>
            <vendorname_indexer>
                <class>Vendorname_Indexer_Model</class>
            </vendorname_indexer>
        </models>
    </global>
    <crontab>
        <jobs>
            <vendorname_indexer>
                <schedule>
                    <cron_expr>0 0 * * *</cron_expr>
                </schedule>
                <run>
                    <model>vendorname_indexer/cron::run</model>
                </run>
            </vendorname_indexer>
        </jobs>
    </crontab>
</config>

app/code/local/Vendorname/Indexer/Model/Cron.php

<?php
class Vendorname_Indexer_Model_Cron {

    public function run() {

        $indexingProcesses = Mage::getSingleton('index/indexer')->getProcessesCollection(); 
        foreach ($indexingProcesses as $indexingProcess) {
            $indexingProcess->reindexEverything();
        }

    }

}

The whole thing is basically doing nothing else than registering a new scheduled task (see the crontab-node in the config.xml) and executing all indexing processes (Cron.php). (Note that this will re-index everything (by default this would be Product Attributes, Product Prices, Catalog URL Rewrites, Category Products, Catalog Search Index, Stock Status, Tag Aggregation Data) so you may want to pick only particular indexing processes in Cron.php based on the indexer code).

In this case you could furthermore easily modify the run() function to first of all execute your import task and in a second step execute the indexing process (the way how you do this obviously will depend on your import script).

1

Use cron to schedule reindexing like below

0 6 * * * php -f /shell/indexer.php reindexall

Set specific time to execute cron.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.