如何在Magento模块中设置Cron作业? [英] How to setup a cron job in Magento module?

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

问题描述

我想在模块内设置一个cron作业.我按照Magento Wiki上的说明进行操作- how_to_setup_a_cron_job ,但是我的cron作业根本没有执行.

I wanted to setup a cron job inside my module. I followed the instructions on Magento wiki - how_to_setup_a_cron_job, but my cron job is simply not executing.

这是我的config.xml(应用程序/代码/本地/Roomstory/发票/etc/config.xml)

This is my config.xml (app/code/local/Roomstory/Invoice/etc/config.xml)

<?xml version="1.0"?>
<config>    
    <modules>
        <Roomstory_Invoice>
            <version>0.1.1</version>
        </Roomstory_Invoice>
    </modules>
<!-- -->
    <crontab>
        <jobs>
            <roomstoryinvoice_setstatus>
                <schedule><cron_expr>*/10 * * * *</cron_expr></schedule>
                <run><model>roomstory_invoice/setstatus::run</model></run>
            </roomstoryinvoice_setstatus>
        </jobs>
    </crontab>
</config>

这是我的课程. (应用程序/代码/本地/Roomstory/发票/模型/Setstatus.php)

And this is my class. (app/code/local/Roomstory/Invoice/Model/Setstatus.php)

<?php
class Roomstory_Invoice_Model_Setstatus {

  public function run() {
    return true;
  }

}
?>

我已经安装了Cron Scheduler模块,该模块显示了我的cron作业,但是当我尝试立即运行"(用于调试)时,出现错误-

I have installed a Cron Scheduler Module, which shows my cron job listed, but when I try to "run now" (for debugging), I get error -

无效的回调:roomstory_invoice/setstatus :: run不存在

Invalid callback: roomstory_invoice/setstatus::run does not exist

这很简单,经过大量尝试,我仍然找不到错误.请告诉其他方法,或者在此代码中指出错误.

This something simple, after much trying, I am still not able to find the error. Please tell some other way to do it, or indicate the error in this code.

谢谢!

推荐答案

在模块config.xml中放置以下内容:

In your modules config.xml put the following:

<config>
    <global>
        <models>
            <roomstoryinvoicecron>
                <class>Roomstory_Invoice_Model</class>
            </roomstoryinvoicecron>                         
        </models>
    </global>
    <crontab>
        <jobs>
            <roomstoryinvoicecron>
                <schedule>
                    <cron_expr>*/10 * * * *</cron_expr>
                </schedule>
                <run>
                    <model>roomstoryinvoicecron/observer::setStatus</model>
                </run>
            </roomstoryinvoicecron>
        </jobs>
    </crontab>
</config>

app/code/local/Roomstory/Invoice/Model/Observer.php中添加以下内容:

<?php
class Roomstory_Invoice_Model_Observer {
    public function setStatus() {
        Mage::log("WORKS!");
    }
}

确保已启用日志记录,并且应该可以正常工作,请检查日志以确保;)

Make sure logging is enabled and it should work, check the log to be sure ;)

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

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