如何在 Magento 模块中设置 cron 作业?

How to setup a cron job in Magento module?(如何在 Magento 模块中设置 cron 作业?)
本文介绍了如何在 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 (app/code/local/Roomstory/Invoice/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>

这是我的课.(app/code/local/Roomstory/Invoice/Model/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 调度程序模块,它显示了我列出的 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 中添加以下内容:

In app/code/local/Roomstory/Invoice/Model/Observer.php add the following:

<?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 作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)