1

cron_groups.xml

<?xml version="1.0"?>
<group id="custom_crongroup">
    <schedule_generate_every>5</schedule_generate_every>
    <schedule_ahead_for>10</schedule_ahead_for>
    <schedule_lifetime>15</schedule_lifetime>
    <history_cleanup_every>10</history_cleanup_every>
    <history_success_lifetime>60</history_success_lifetime>
    <history_failure_lifetime>600</history_failure_lifetime>
    <use_separate_process>1</use_separate_process>
</group>

crontab.xml

<?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="custom_crongroup">
        <job name="monthly_commission" instance="Rewamp\Promotion\Cron\Run" method="execute">
            <schedule>*/5 * * * *</schedule>
        </job>
    </group>

This cusotm cron is working correctly when i run the cron,

php bin/magento cron:run

from terminal. But i need to run the cron automatically in every 5 minutes. how can i implement this?.

0

If it's successfully working from terminal, then you need to set up the actual server cron job to run the command.

Have the cron command run every 1 minute. You're custom cron job however will still only run every 5 minutes because Magento knows when it should be ran.

Below is documentation from the Magento themselves instructing how to do so:

http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.html

0

Maybe this is your idea.

  1. Check cronjob installed in your environment

crontab -i

You can install cronjob in ubuntu with command

sudo apt install cron

  1. Install magento cronjob

Go to magento workspace and run command line:

php bin/magento cron:remove

php bin/magento cron:install

  1. Check Magento cron is installed in the environment

crontab -l

  1. Open Mysql and check cron is worked
SELECT * FROM `cron_schedule`
0
1. Open terminal 
2. write a command crontab -e 
3. write below command

* * * * * /usr/bin/php /var/www/html/magento2/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/update/cron.php >> /var/www/html/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/html/magento2/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log

Note :- check your php and magento 2 folder path according to your project.

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.