6

I need to override a crontab.xml from:

vendor/magento/module-integration/etc/crontab.xml

    <job name="expired_tokens_cleanup" instance="Magento\Integration\Cron\CleanExpiredTokens" method="execute">
        <schedule>0 * * * *</schedule>
    </job>

To

    <job name="expired_tokens_cleanup" instance="Magento\Integration\Cron\CleanExpiredTokens" method="execute">
        <schedule>*/15 * * * *</schedule>
    </job>

The question is... Which is the best way to do it?

I have already created a file in the path app/design/frontend/[Vendor]/[theme]/Magento_Integration/etc/crontab.xml but nothing change.

Greetings.

4 Answers 4

1

do same entry into core_config_data with same cron expression, it will override that.

1

You should create an extension having etc/crontab.xml file

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
    <group id="default">
        <job name="expired_tokens_cleanup" instance="Magento\Integration\Cron\CleanExpiredTokens" method="execute">
        <schedule>*/15 * * * *</schedule>
    </job>
    </group>
</config>

This should work.

1

Most hosting use a crontab file somewhere where you can put your settings in. If you are using a hosting you should ask them where and how you can adjust it. Because the cron is executed server side this is the only way to do that.

If you want to adjust the settings in the backend how Magento generates cron tasks (this is for generating cron tasks , not executing them) you have 2 options.

1. Manually

Adjust them manually under Stores->Settings->Configuration->Advanced->System

2. By module

Create a module and use a etc/config.xml to set the default settings of those fields. Remember that a user can always overwrite them manually.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <cron>
            <template>
                <schedule_generate_every>500</schedule_generate_every>
.....
            </template>
        </cron>
</config>

You can find all available fields under vendor/magento/module-cron/etc/adminhtml/system.xml

0
0

You can insert a new configuration expression on the DB, above is the query you can use for that

default: it is the group_id of your job your_job_name: it is the name of your job

INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, `path`, `value`, `updated_at`) VALUES (NULL, 'default', '0', 
'crontab/default/jobs/your_job_name/schedule/cron_expr', '00 02,12,22 * * *', '2024-01-24 10:02:49');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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