magento cron job和cron_scheduler表

时间:2021-10-18 08:01:36

I made magento module which export product in csv file. Now i want to run cronjob every day at 23.55. I set config.xml as it is written in magento cronjob wiki.

我制作了magento模块,用于在csv文件中导出产品。现在我想每天23.55运行cronjob。我设置了config.xml,因为它是用magento cronjob wiki编写的。

My code:

我的代码:

<crontab>
        <jobs>
            <gcompany_runprofilescronjob>
                <schedule>
                    <cron_expr>55 23 * * *</cron_expr>
                </schedule>
                <run>
                    <model>export/export_csv::runprofilescronjob</model>
                </run>
            </gcompany_runprofilescronjob>
        </jobs>
    </crontab> 

I also set cronjob on server. When cronjob run, all cronjobs in magento are stored in database table cron_schedule but not my gcompany_runprofilescronjob. If i set different interval for example:

我还在服务器上设置了cronjob。当cronjob运行时,magento中的所有cronjobs都存储在数据库表cron_schedule中,但不存储在我的gcompany_runprofilescronjob中。如果我设置不同的间隔,例如:

<cron_expr>*/1 * * * *</cron_expr>

My cronjob is written in database but in execute every minute which i don't want... I want that my function is executed every day at 23.55. Any suggestions what i am doing wrong?

我的cronjob是用数据库写的,但每分钟执行一次,我不想要......我希望我的功能每天都在23.55执行。有什么建议我做错了吗?

2 个解决方案

#1


7  

Although this is a very old question, there is no correct answer posted, so let me leave this here for the next guy.

虽然这是一个非常古老的问题,但没有正确的答案,所以让我把这个留给下一个人。

Magento's cron_schedule table is only populated with cron jobs that are scheduled to run in the near future. The reason you're not seeing your cron job in the table is because it only runs once a day, precisely at 23:55. Magento will add this cron job to the cron_schedule table at around 23:45, depending on your server cron job configuration and Magento's cron job settings in System > Configuration > System > Cron. Take note of the Generate Schedules Every and Schedule Ahead for settings, which define how often and how far ahead Magento generates the schedule.

Magento的cron_schedule表只填充了计划在不久的将来运行的cron作业。你没有在表中看到你的cron工作的原因是因为它每天只运行一次,正好是在23:55。 Magento将在23:45左右将此cron作业添加到cron_schedule表中,具体取决于您在System> Configuration> System> Cron中的服务器cron作业配置和Magento的cron作业设置。记下“生成每个时间表”和“提前安排”设置,这些设置定义了Magento生成时间表的频率和范围。

#2


4  

My first step would be to install Fabrizio Branca's AOE Scheduler extension. Fabrizio's extension has a "List View" feature that will show you all of the Cron jobs currently registered with Magento's cron, and when they are scheduled to run. It also allows you to run a cron job immediately in your browser (great for debugging cron jobs), or schedule the job for immediate execution.

我的第一步是安装Fabrizio Branca的AOE Scheduler扩展。 Fabrizio的扩展程序具有“列表视图”功能,该功能将向您显示当前在Magento的cron中注册的所有Cron作业,以及它们何时计划运行。它还允许您立即在浏览器中运行cron作业(非常适合调试cron作业),或安排作业立即执行。

If your cron job doesn't appear in AOE Scheduler's list view, there's an issue with the configuration of the cron job. Try clearing the config cache to make sure Magento will parse your config.xml for the latest changes. I assume your XML node is in the appropriate place in the XML document's hierarchy, i.e. directly under the <config> node?

如果您的cron作业未出现在AOE Scheduler的列表视图中,则cron作业的配置存在问题。尝试清除配置缓存以确保Magento将解析您的config.xml以获取最新更改。我假设您的XML节点位于XML文档层次结构中的适当位置,即直接位于 节点下?

If your cron job appears in List View and still doesn't run, use the "Generate Schedule" feature to regenerate the cron scheduling tables. Also try running your cron job manually using AOE Scheduler's "Run Now" feature to check for errors or exceptions.

如果您的cron作业出现在列表视图中但仍未运行,请使用“生成计划”功能重新生成cron计划表。还可以尝试使用AOE Scheduler的“立即运行”功能手动运行您的cron作业,以检查错误或异常。

#1


7  

Although this is a very old question, there is no correct answer posted, so let me leave this here for the next guy.

虽然这是一个非常古老的问题,但没有正确的答案,所以让我把这个留给下一个人。

Magento's cron_schedule table is only populated with cron jobs that are scheduled to run in the near future. The reason you're not seeing your cron job in the table is because it only runs once a day, precisely at 23:55. Magento will add this cron job to the cron_schedule table at around 23:45, depending on your server cron job configuration and Magento's cron job settings in System > Configuration > System > Cron. Take note of the Generate Schedules Every and Schedule Ahead for settings, which define how often and how far ahead Magento generates the schedule.

Magento的cron_schedule表只填充了计划在不久的将来运行的cron作业。你没有在表中看到你的cron工作的原因是因为它每天只运行一次,正好是在23:55。 Magento将在23:45左右将此cron作业添加到cron_schedule表中,具体取决于您在System> Configuration> System> Cron中的服务器cron作业配置和Magento的cron作业设置。记下“生成每个时间表”和“提前安排”设置,这些设置定义了Magento生成时间表的频率和范围。

#2


4  

My first step would be to install Fabrizio Branca's AOE Scheduler extension. Fabrizio's extension has a "List View" feature that will show you all of the Cron jobs currently registered with Magento's cron, and when they are scheduled to run. It also allows you to run a cron job immediately in your browser (great for debugging cron jobs), or schedule the job for immediate execution.

我的第一步是安装Fabrizio Branca的AOE Scheduler扩展。 Fabrizio的扩展程序具有“列表视图”功能,该功能将向您显示当前在Magento的cron中注册的所有Cron作业,以及它们何时计划运行。它还允许您立即在浏览器中运行cron作业(非常适合调试cron作业),或安排作业立即执行。

If your cron job doesn't appear in AOE Scheduler's list view, there's an issue with the configuration of the cron job. Try clearing the config cache to make sure Magento will parse your config.xml for the latest changes. I assume your XML node is in the appropriate place in the XML document's hierarchy, i.e. directly under the <config> node?

如果您的cron作业未出现在AOE Scheduler的列表视图中,则cron作业的配置存在问题。尝试清除配置缓存以确保Magento将解析您的config.xml以获取最新更改。我假设您的XML节点位于XML文档层次结构中的适当位置,即直接位于 节点下?

If your cron job appears in List View and still doesn't run, use the "Generate Schedule" feature to regenerate the cron scheduling tables. Also try running your cron job manually using AOE Scheduler's "Run Now" feature to check for errors or exceptions.

如果您的cron作业出现在列表视图中但仍未运行,请使用“生成计划”功能重新生成cron计划表。还可以尝试使用AOE Scheduler的“立即运行”功能手动运行您的cron作业,以检查错误或异常。