1

I would like to take the value of the ahead schedule of this system.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
    <section id="system">
        <group id="cron" translate="label comment" type="text" sortOrder="15" showInDefault="1" showInWebsite="0" showInStore="0">
            <label>Cron (Scheduled Tasks)</label>
            <comment>For correct URLs generated during cron runs please make sure that Web &gt; Secure and Unsecure Base URLs are explicitly set. All the times are in minutes.</comment>
            <group id="template" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Cron configuration options for group: </label>
                <field id="schedule_generate_every" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                    <label>Generate Schedules Every</label>
                </field>
                <field id="schedule_ahead_for" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                    <label>Schedule Ahead for</label>
                </field>
                <field id="schedule_lifetime" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                    <label>Missed if Not Run Within</label>
                </field>
                <field id="history_cleanup_every" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                    <label>History Cleanup Every</label>
                </field>
                <field id="history_success_lifetime" translate="label" type="text" sortOrder="50" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                    <label>Success History Lifetime</label>
                </field>
                <field id="history_failure_lifetime" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                    <label>Failure History Lifetime</label>
                </field>
                <field id="use_separate_process" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
                    <label>Use Separate Process</label>
                    <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
                </field>
            </group>
        </group>
    </section>
</system>

I tried this command in a controller

$scheduleAheadFor = $this->scopeConfig->getValue('system/cron/schedule_ahead_for', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

but it did not work. Someone who can help me?

2

It seems you are missing the template part from the config path. Try this:

$scheduleAheadFor = $this->scopeConfig->getValue('system/cron/template/schedule_ahead_for', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);

  • is the first thing that I thought too. I tried $ this-> scopeConfig-> getValue ('system / cron / template / schedule_ahead_for', Magento Store ScopeInterface :: SCOPE_STORE); but returns null. – Mastafis Aug 8 at 9:30
  • 1
    You need to replace template with your cron's group id – Tsita Aug 8 at 9:37
  • It worked! thanks @Tsita – Mastafis Aug 8 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.