1

I am trying to run custom cron but, I got below error in system.log while execute cron:run command.

main.WARNING: Could not acquire lock for cron group: default, skipping run [] []

crontab.xml file

<group id="default">
        <job name="test_cron" instance="Vendor\Module\Cron\Test" method="execute">
            <schedule>* * * * *</schedule>
        </job>
</group>

Cron/Test.php

namespace Vendor\Module\Cron;

class Test {

    public function execute() {

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/customcron.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info("cron works");
   }
}

1 Answer 1

0

crontab.xml file

  <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="test_cron" instance="Vendor\Module\Cron\Test" method="execute">
                <schedule>*/15 * * * *</schedule>
            </job>            
        </group>
    </config>

Cron/Test.php

namespace  Vendor\Module\Cron;

class Test
{
    public function execute()
    {
       $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/customcron.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);
        $logger->info("cron works");
        return $this;
    }
}

I think your code is almost right. Please recheck your code and then flush cache.

php bin/magento cache:flush

Run the indexing cron job

bin/magento cron:run --group index

Run the default cron job

bin/magento cron:run --group default

check link https://devdocs.magento.com/guides/v2.3/config-guide/cli/config-cli-subcommands-cron.html

If it's not work please check your table "cron_schedule"

 SELECT * FROM cron_schedule where job_code='test_cron';

If you found any records? then delete that records and run all commands again.

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.