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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)