magemojo / m2-ce-cron

Magento 2 cron project to fix bugs and common cron issues.
https://magemojo.com
MIT License
165 stars 45 forks source link

No cron jobs will run when catalogrule_apply_all is processing #112

Closed zjevik closed 3 years ago

zjevik commented 3 years ago

Hi,

I seem to have an issue that no CRON jobs are run when catalogrule_apply_all is running.

I have the following error from cron:

[2021-01-10 05:21:03] INFO Healthchecking Cron Service
[2021-01-10 05:21:04] INFO Running Process Cleanup
[2021-01-10 05:21:04] INFO Running Consumers Cleanup
[2021-01-10 05:21:04] INFO Starting Cron Service

In ErrorHandler.php line 61:

  Notice: Undefined offset: 8874 in /var/www/html/vendor/magemojo/m2-ce-cron/
  Model/Schedule.php on line 474

cron:run [--group GROUP] [--bootstrap BOOTSTRAP]

And the appropiate error in system.log:

[2021-01-10 05:21:04] main.ERROR: Notice: Undefined offset: 8874 in /var/www/html/vendor/magemojo/m2-ce-cron/Model/Schedule.php on line 474
#0 /var/www/html/vendor/magemojo/m2-ce-cron/Model/Schedule.php(474): Magento\Framework\App\ErrorHandler->handler(8, 'Undefined offse...', '/var/www/html/v...', 474, Array)
#1 /var/www/html/vendor/magemojo/m2-ce-cron/Model/Schedule.php(517): MageMojo\Cron\Model\Schedule->getJob('8874')
#2 /var/www/html/vendor/magemojo/m2-ce-cron/Model/Schedule.php(368): MageMojo\Cron\Model\Schedule->service()
#3 /var/www/html/generated/code/MageMojo/Cron/Model/Schedule/Proxy.php(207): MageMojo\Cron\Model\Schedule->execute()
#4 /var/www/html/vendor/magemojo/m2-ce-cron/Console/Command/CronCommand.php(75): MageMojo\Cron\Model\Schedule\Proxy->execute()
#5 /var/www/html/vendor/symfony/console/Command/Command.php(255): MageMojo\Cron\Console\Command\CronCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(58): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(138): MageMojo\Cron\Console\Command\CronCommand\Interceptor->___callParent('run', Array)
#8 /var/www/html/vendor/magento/framework/Interception/Interceptor.php(153): MageMojo\Cron\Console\Command\CronCommand\Interceptor->Magento\Framework\Interception\{closure}(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /var/www/html/generated/code/MageMojo/Cron/Console/Command/CronCommand/Interceptor.php(23): MageMojo\Cron\Console\Command\CronCommand\Interceptor->___callPlugins('run', Array, Array)
#10 /var/www/html/vendor/symfony/console/Application.php(1009): MageMojo\Cron\Console\Command\CronCommand\Interceptor->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/html/vendor/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(MageMojo\Cron\Console\Command\CronCommand\Interceptor), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/html/vendor/magento/framework/Console/Cli.php(115): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/vendor/symfony/console/Application.php(149): Magento\Framework\Console\Cli->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/bin/magento(23): Symfony\Component\Console\Application->run()
#15 {main} [] []

any help to debug this is appreciated

jaxtheking commented 3 years ago

I came here to report the same exact problem, only to discover @zjevik already opened an issue.

After (re-)starting the cron, it seems to last exactly an hour when this error is raised again. After that, cron jobs are no longer run and the cron needs restarting manually.

I was not able to debug it, but I did notice that:

I'm not sure if my observation above means anything as I'm not sure if catalogrule_apply_all is the cause of this error for me (as I don't have it in my schedule).

Luca

zjevik commented 3 years ago

Following on @jaxtheking I tried to run this module on a clean 2.4.1 installation and the errors go in and out quite randomly. The Cron will stop working for 20 minutes, then works for some time and then doesn't work, etc.

The behaviour is quite strange but one shouldn't install this module in the current version on 2.4.1

jaxtheking commented 3 years ago

Hi @zjevik, I think I managed to keep the crons going by basically reverting commit https://github.com/magemojo/m2-ce-cron/pull/111/commits/b61a48113d64810596cb782852f5ca303f511fb9.

I traced the problem to the service loop, where the code checks for running jobs (determined by the presence of a file in var/cron e.g. cron.4385). However, when the schedule id is passed to getJob, that function throws an error if - or should I say when - said schedule id does not exist within the pendingjobs array.

Therefore, try replacing the getJob function in vendor/magemojo/m2-ce-cron/Model/Schedule.php with the following to see if the cron jobs keep running:

    /**
     * Set a job by schedule id
     *
     * @return array
     */
    function getJob($scheduleid) {      
      if (in_array($scheduleid, $this->pendingjobs)) {
        return $this->pendingjobs[$scheduleid];
      }
      return NULL;
    }

I'd be curious to see if it works for you too...

zjevik commented 3 years ago

@jaxtheking I figure out my issue with the default cron runner and I no longer need to use this module. See https://github.com/magento/magento2/issues/31752

This is no longer my priority and won't be probably using this module in the future. I have 1M+ products and any debugging is very time consuming.

I will try to make the change in my development system in the future but it might take some time.

jaxtheking commented 3 years ago

I can confirm that reverting commit https://github.com/magemojo/m2-ce-cron/commit/b61a48113d64810596cb782852f5ca303f511fb9 solved the issue for me and that the cron jobs have now been running for the last 10 days without stopping.

Could I ask for your input @gnuzealot? Can you see why the changes in that commit would cause the problems described in this issue and evaluate if it's the case to revert it?

Thanks, Luca

gnuzealot commented 3 years ago

This should be resolved with https://github.com/magemojo/m2-ce-cron/pull/114