在Magento中设置CRON作业 [英] Setting up CRON job in Magento

查看:137
本文介绍了在Magento中设置CRON作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多教程用于设置cron,我认为我已经正确地做了,但由于某种原因它不工作。我还创建了一个控制器类来测试模型,它的工作正常。

There are plenty of tutorials out there for setting up cron, and I think I've done it correctly, but for some reason it isn't working. I have also created a controller class to test the model and it's working correctly.

这是我的config.xml:

Here's my config.xml:

<config>
    <modules>
        <VPS_Export>
            <version>0.1.0</version>
        </VPS_Export>
    </modules>
    <global>
        <models>
            <vps_export>
                <class>VPS_Export_Model</class>
            </vps_export>
        </models>
        <helpers>
            <vps_export>
                <class>VPS_Export_Helper</class>
            </vps_export>
        </helpers>
    </global>
<frontend>
    <routers>
        <vps_export>
            <use>standard</use>
            <args>
                <module>VPS_Export</module>
                <frontName>vpsexport</frontName>
            </args>
        </vps_export>
    </routers>  
</frontend>
    <crontab>
        <jobs>
            <vps_export>
                <schedule>
                    <cron_expr>*/5 * * * *</cron_expr><!-- every 5 minutes -->
                </schedule>
                <run>
                    <model>vps_export/observer::exportProducts</model>
                </run>
            </vps_export>
        </jobs>
    </crontab>
</config>

我的Observer.php文件是:

My Observer.php file is:

<?php
class VPS_Export_Model_Observer
{
    public function exportProducts()
    {
        echo "VPS Export Products called!";
        Mage::Log("exportProducts called!");
    }
}
?>

我的测试IndexController.php文件是:

And my test IndexController.php file is:

<?php
class VPS_Export_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        echo "index action called!";
        Mage::getModel('vps_export/observer')->exportProducts();
    }
}
?>

如果我将浏览器指向 http:// my_server / vpsexport / index 我看到echo语句的正确输出,消息被打印到日志,所以我知道模型已正确配置。然而,cron没有相同的结果。如果我手动运行cron.php,我没有错误,但它似乎没有做任何事情。

If I point my browser at http://my_server/vpsexport/index I see the proper output from the echo statements and the message gets printed to the log, so I know the model is properly configured. However, cron is not having the same results. If I run cron.php manually, I get no errors, but it still doesn't seem to do anything.

任何想法?

推荐答案

据我理解magento的cron系统,它工作在两个阶段:

As far as I understand magento's cron system, it works in 2 phase:


  1. 它检查模块config.xml以找出必须由cron运行的方法,并将它们插入数据库( cron_schedule

  2. 它从此表中获取信息,并运行与实际时间匹配的 scheduled_at 列。

  1. it checks the modules config.xml to find out the methods which have to be run by cron and insert them into the database (cron_schedule)
  2. it get the info from this table and run the methods matching the scheduled_at column with actual time.

正如你所说,你的 cron_schedule 表中有条目,第一阶段是确定

要检查您的cron是否执行正常,您实际上必须在您的服务器中设置一个cronjob,如果您在本地工作,这将是您的计算机。

这在ubuntu实际上很简单,我想它会在窗口上更复杂,但是(再次猜测)不可能。

或者也许刷新您的浏览器指向cron.php文件几次,每5分钟(因为你在config.xml中配置它)

As you say there are entries in your cron_schedule table, the first phase is ok
So in order to check if your cron executes fine, you actually have to setup a cronjob in your server, which would be your computer if you're working locally.
It's actually very simple on ubuntu, I guess it will be more complicated on windows, but (guessing again) not imposible.
Or maybe refreshing your browser pointing to your cron.php file a few times would every 5 minutes (as you have it configured in your config.xml) would do the trick, but setting up a cronjob would be quite more eficient :)
Hope That Helps

编辑:

edit: here is waht my cronjob looks like, if it helps you:

*/5 * * * * wget -q http://magento.local/cron.php

这篇关于在Magento中设置CRON作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆