本文介绍了后端配置中的 magento cron的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道如何使用 config.xml crontab 内容设置 cron:

So I know how to setup a cron using the config.xml crontab stuff:

<crontab>
    <jobs>
        <millena_export_send_all>
            <schedule><cron_expr>* * * * *</cron_expr></schedule>
            <run><model>millena_export/observer::exportOrderData</model></run>
        </millena_export_send_all>
    </jobs>
</crontab>

但让我感到困惑的是如何使 cron_expr 成为后端中可以更改的设置(每 5 分钟、每 10 分钟等).我想我可以使用 backend_model 然后在 after_save 方法中我可以做 setStoreConfig('path/to/schedule/cron_expr', '*/5 * * * *') 或类似的东西,它会保存在缓存.我的想法正确吗?有没有更好的方法来做到这一点?

But what I am confused about is how to make that cron_expr a setting in the backend that can be changed (every 5 minutes, every 10 minutes, etc). I am thinking I can use a backend_model and then in an after_save method I can do setStoreConfig('path/to/schedule/cron_expr', '*/5 * * * *') or something to that sort and it will save in the cache. Is my thinking correct? Is there a better way to do this?

推荐答案

不涉及自定义后端模型的更好解决方案.

A better solution that doesn't involve a custom backend model.

配置文件

<?xml version="1.0"?>   
<config>
    <modules>
        <Company_Export>
            <version>0.1.0</version>
        </Company_Export>
    </modules>
    <global>
        <models>
            <company_export>
                <class>Company_Export_Model</class>
            </company_export>
        </models>
    </global>
    <default>
        <export>                
            <order>
                <cron_settings>*/5 * * * *</cron_settings>
            </order>
        </export>
    </default>
    <crontab>
        <jobs>                
            <company_export_send_order>
                <schedule>
                    <config_path>export/order/cron_settings</config_path>
                </schedule>
                <run>
                    <model>company_export/observer::exportOrderData</model>
                </run>
            </company_export_send_order>
        </jobs>
    </crontab>
</config>

system.xml

<?xml version="1.0"?>
<config>
    <tabs>
        <feedsconfig translate="label" module="export">
            <label>Feeds Configuration</label>
            <sort_order>99999</sort_order>
        </feedsconfig>
    </tabs>
    <sections>
        <export translate="label" module="export">
            <label>Export</label>
            <tab>feedsconfig</tab>
            <frontend_type>text</frontend_type>
            <sort_order>10000</sort_order>
            <show_in_default>1</show_in_default>
            <groups>
                <order translate="label">
                    <label>Order</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>2</sort_order>
                    <show_in_default>1</show_in_default>
                    <fields>
                         <cron_settings>
                            <label>How often do you want the cron to run?</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>40</sort_order>
                            <comment>Use Crontab Format (Eg. "*/5 * * * *" for every 5 minutes)</comment>
                            <show_in_default>1</show_in_default>
                        </cron_settings>
                    </fields>
                </order>
            </groups>
        </export>
    </sections>
</config>

这篇关于后端配置中的 magento cron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 23:46