1

I am trying to create a cronjob that will run my script (which imports an XML files) on a set time. For now I put it to run every 2 min., just for testing purposes.

What I've done is just add the following code in the config.xml of the particular module, that takes care of the importing:

<crontab>
        <jobs>
            <productimporter_import_xml>
                <schedule>
                    <cron_expr>*/2 * * * *</cron_expr>
                </schedule>
                <run>
                    <model>productimporter/catalog_importer::_importFile</model>
                </run>
            </productimporter_import_xml>
        </jobs>
    </crontab>

So, the module in the local code is called ProductImporter, and the script is ProductImporter/Model/Catalog/Importer.php and _importFile is the initial function.

Apparently this doesn't work. Is there something else that has to be set, additionally to the config.xml? Or maybe I haven't done my setting correctly (perhaps the path), I don't a real clue...

  • The above configuration is for Magento's internal crontab system. The actual execution relies on your system's cron set up (it should either call cron.php or cron.sh both in Magento's root folder) - please check and confirm that this is running and working in general. – Kristof at Fooman Feb 17 '14 at 21:56
2

There are some extra steps for certain systems here.

I seem to remember reading somewhere that even if you set a cronjob to run every couple of minutes it will still only run every 5 minutes or more, although I can't confirm this.

EDIT: The cron jobs have their individual run times but there is also a schedule generation time which will generate the list of jobs (every 15mins on our server), meaning that if the schedule has just been generated and you then create a job for every 5 minutes, you would have to wait until the schedule is generated again for the job to work.

enter image description here

  • Doesn't matter, because I've waited more than 5 min. But thanks! I will try on with the info from the link you gave me. Just one more question - is the path set correctly? productimporter/catalog_importer::_importFile or it has to be without catalog as the script file is located as follows: ...Model/Catalog/Importer.php ? – Syspect Jan 6 '14 at 16:03
  • I'm afraid I am not sure but my instinct would be to say without "catalog". Can you try both? Note as well I have just edited my answer. – James Jan 6 '14 at 16:16
1

Your config looks ok as far as I see. I wonder if your function _importFile is public, as many ppl tend to use the _ to identify protected or private methods.

For debugging cronjobs I use this magento module http://www.magentocommerce.com/magento-connect/aoe-scheduler.html

it allows you to execute a specific cronjob by its code, so you could call it on cli via:
php shell/scheduler.php -action runNow -code productimporter_import_xml

If this works, but not the cron, try to execute the cron.php once a minute for a few minutes and see what happens in the database table cron_schedule.

Your Answer

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

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