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.
我想在我的模块中设置cron作业。我遵循了Magento wiki上的说明——how_to_setup_a_cron_job,但是我的cron job就是不执行。
This is my config.xml (app/code/local/Roomstory/Invoice/etc/config.xml)
这是我的配置。xml(app /代码/地方/ Roomstory /发票/ 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>
And this is my class. (app/code/local/Roomstory/Invoice/Model/Setstatus.php)
这是我的课。(app /代码/地方/ Roomstory /发票/模型/ Setstatus.php)
<?php
class Roomstory_Invoice_Model_Setstatus {
public function run() {
return true;
}
}
?>
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 -
我已经安装了Cron调度器模块,它显示了列出的Cron作业,但是当我尝试“现在运行”(用于调试)时,我得到了错误-
Invalid callback: roomstory_invoice/setstatus::run does not exist
无效回调:roomstory_invoice/setstatus: run不存在
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.
这事很简单,经过多次尝试,我还是找不到错误。请告诉其他方法,或在此代码中指出错误。
Thanks!
谢谢!
5 个解决方案
#1
34
In your modules config.xml
put the following:
在你的模块配置。xml将以下:
<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>
In app/code/local/Roomstory/Invoice/Model/Observer.php
add the following:
在app /代码/地方/ Roomstory /发票/模型/观察者。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 ;)
确保日志记录是启用的,并且它应该工作,检查日志以确定;
#2
7
Be sure to add Magento cron.sh file in crontab
一定要加上魔咒克伦。在crontab sh文件
crontab -e
*/5 * * * * /bin/sh /path-to-magento/cron.sh
#3
2
<crontab>
<jobs>
<CompanyName_ModuleName>
<schedule>
<cron_expr>*/5 * * * *</cron_expr>
</schedule>
<run>
<model>ModuleName/observer::setStatus</model>
</run>
</CompanyName_ModuleName>
</jobs>
</crontab>
and create Observer.php file in Model with
并创建观察者。php文件的模型
class CompanyName_ModuleName_Model_Observer extends Mage_Core_Model_Abstract
{
public function setStatus()
{
}
}
#4
1
You can easily create a module for cron job just follow the following steps:
您可以轻松地为cron job创建一个模块,只需遵循以下步骤:
Create Config.xml file and set cron job in it.
创建配置。xml文件并在其中设置cron作业。
<?xml version="1.0"?>
<config>
<crontab>
<jobs>
<Namespace_Module>
<schedule>
<cron_expr>* * * * *</cron_expr>
</schedule>
<run>
<model>module/observer::method</model>
</run>
</Namespace_Module>
</jobs>
</crontab>
</config>
Your observer method:
你的观察方法:
class CompanyName_ModuleName_Model_Observer extends Mage_Core_Model_Abstract
{
public function setStatus()
{
//your action
}
}
now last step go to your hosting cpanel and set path and run time of cron.php file in cron job section
现在,最后一步进入您的托管cpanel,设置cron的路径和运行时间。cron作业部分中的php文件
by default you can set path like php -f /home/mercodec/public_html/cron.php
in magento.
默认情况下,可以设置php -f /home/mercodec/public_html/cron等路径。php的线上购物。
#5
0
before that you have to run this script in your terminal. For ubuntu:*/1 * * * * /usr/bin/php /var/www/html/modulename/cron.php > /dev/null
在此之前,您必须在终端中运行此脚本。对于ubuntu:*/1 * * * * */ usr/bin/php / var/www/html/modulename/cron。php > / dev / null
#1
34
In your modules config.xml
put the following:
在你的模块配置。xml将以下:
<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>
In app/code/local/Roomstory/Invoice/Model/Observer.php
add the following:
在app /代码/地方/ Roomstory /发票/模型/观察者。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 ;)
确保日志记录是启用的,并且它应该工作,检查日志以确定;
#2
7
Be sure to add Magento cron.sh file in crontab
一定要加上魔咒克伦。在crontab sh文件
crontab -e
*/5 * * * * /bin/sh /path-to-magento/cron.sh
#3
2
<crontab>
<jobs>
<CompanyName_ModuleName>
<schedule>
<cron_expr>*/5 * * * *</cron_expr>
</schedule>
<run>
<model>ModuleName/observer::setStatus</model>
</run>
</CompanyName_ModuleName>
</jobs>
</crontab>
and create Observer.php file in Model with
并创建观察者。php文件的模型
class CompanyName_ModuleName_Model_Observer extends Mage_Core_Model_Abstract
{
public function setStatus()
{
}
}
#4
1
You can easily create a module for cron job just follow the following steps:
您可以轻松地为cron job创建一个模块,只需遵循以下步骤:
Create Config.xml file and set cron job in it.
创建配置。xml文件并在其中设置cron作业。
<?xml version="1.0"?>
<config>
<crontab>
<jobs>
<Namespace_Module>
<schedule>
<cron_expr>* * * * *</cron_expr>
</schedule>
<run>
<model>module/observer::method</model>
</run>
</Namespace_Module>
</jobs>
</crontab>
</config>
Your observer method:
你的观察方法:
class CompanyName_ModuleName_Model_Observer extends Mage_Core_Model_Abstract
{
public function setStatus()
{
//your action
}
}
now last step go to your hosting cpanel and set path and run time of cron.php file in cron job section
现在,最后一步进入您的托管cpanel,设置cron的路径和运行时间。cron作业部分中的php文件
by default you can set path like php -f /home/mercodec/public_html/cron.php
in magento.
默认情况下,可以设置php -f /home/mercodec/public_html/cron等路径。php的线上购物。
#5
0
before that you have to run this script in your terminal. For ubuntu:*/1 * * * * /usr/bin/php /var/www/html/modulename/cron.php > /dev/null
在此之前,您必须在终端中运行此脚本。对于ubuntu:*/1 * * * * */ usr/bin/php / var/www/html/modulename/cron。php > / dev / null