Weekly Drupal cron task exiting unexpectedly, Drupal not reporting error

I have my doubts that this problem is actually caused by my Drupal configuration, but am wondering if anyone else has experienced a similar issue and how they went (or would go about) troubleshooting it.

I am running a production environment with:

  • Drupal 8.6.12
  • Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips
  • PHP/7.1.28
  • memory limit 1028M
  • 5.5.60-MariaDB
  • MySQL, MariaDB, Percona Server, or equivalent.

A staging environment on a different machine with the same code base runs (mostly the same):

  • Drupal 8.6.12
  • Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips mod_fcgid/2.3.9
  • PHP/7.1.27
  • memory limit 1028M
  • 5.5.60-MariaDB
  • MySQL, MariaDB, Percona Server, or equivalent.

I have a cron job that is scheduled (using Crontab scheduling) to run every Sunday at 5 PM EST using Ultimate Cron, scheduled for 0 17 * * 0.

CentOS crontab attempts to run behind-schedule Drupal cron tasks every 15 minutes:

*/15 * * * * wget https://<site domain>/cron/<cron token> --delete-after

About a month ago, this particular cron task started executing multiple times overnight, but only completing on the final attempt. The task sends four e-mails. It has been sending the first e-mail on every execution attempt (13-14 times), but the final three e-mails only upon final completion (once).

The production server takes a full code and DB backup of the site at 1 am. The cron task first tries to run at 5 PM (determined by the timestamp of the sent email), and then tries again at around 6 pm, 7:30 pm, 8:30 pm, etc etc, about every 1-2 hours (always at 0, 15, 30, or 45 minutes past the hour, which makes sense as those times match the contents of my centOS crontab), until it finally finishes at around 7-8 am the next day. I took the 1 am DB backup (at a time when the task had not yet successfully completed, and would not on its next attempt either) and replaced the staging site’s database with it. In Configuration > System > Cron, there was no record on Drupal’s behalf of this task ever having run. Drupal states the task was last run a week prior, so this suggests to me that PHP is exiting completely and Drupal has no chance to log an error message. This seems to explain why it is trying to run multiple times, as if Drupal has no recollection of the task ever having run, it will see the task as being behind schedule and try to run it next time crontab issues wget on the site’s cron URL. (However that doesn’t explain why it only seems to happen once an hour at most, when crontab checks every 15 minutes.)

I am wondering, firstly, if there is anything I can do to get around that and have Drupal record when such a thing happens, but I suspect not as it is happening at the PHP process level. (I do not believe it is caused by exceeding the memory_limit property in php.ini, as I’ve seen that problem before and Drupal would say so in the cron logs if the task had exited for that reason.)

This also suggests to me that the cron is failing to continue running sometime between the first and second e-mail, which makes sense as during this part of the code a very taxing and complicated SQL query is run on the user tables (selects users with a particular role meeting a complicated condition, which then takes loops through the retrieved entity IDs, loads the user, changes a field value, changes the user’s role, and then saves the user), but for whatever reason is succeeding the 14th time. However, according to my database timestamps, the part of the code that updates the user field value and then saves the user is completing on the second or third cron run attempt, so past that it seems that it is just running the query and returning no results (which also makes sense, as the query selects for a particular role, and is changing the role of the users it finds, so there would be no users returned once they’ve all been converted).

The code for this cron task has not changed since October. I am unsure what could have happened.

In my Apache logs, I was seeing several error messages like the following:

Sun Apr 14 18:18:27 2019 (1893): Error Cannot kill process 1169: Success! [Sun Apr 14 18:18:27.170950 2019] [core:notice] [pid 6755] AH00052: child pid 1893 exit signal Segmentation fault (11) 

These error messages were only appearing around the times the cron task was executing. However, looking at the timestamps of the e-mails sent by the cron task, some of them do not have a matching error message in the apache error log.

This error message is bizarre, but it was suggested to me that this is caused by a PHP bug and that I should change my configuration to use php-fpm and the event MPM, which I did on Friday. However, the problem persisted. It is no longer logging segfaults, but now has logged zend_mm_heap corrupted two times with no timestamp, where I can see from the task’s sent emails that it attempted to run 14 times.

The PHP error logs from the site contain no information related to the task exiting.

I have tried simply letting the cron run on the staging environment like the production environment, but it executes correctly with no exits, and never takes longer than ten minutes.

I am at a loss, and wondering if anyone else has experienced a similar issue with Drupal cron jobs, and may have any further recommendations for troubleshooting.

Magento 2 v2.3.1. CRON causing intermittent Deadlock for cron_schedule

Magento 2 v2.3.1. CRON causing intermittent Deadlock for cron_schedule

we installed vanilla M2 some extensions. But default CRON is leading to deadlock warnings. Maybe not critical but should not happen. Also the solution found elsewhere: truncate the table of course only works temporarily. The error will re-occur. Magento should have some kind of deadlock retry mechanism …

Question: is there any way to structurally solve this issue?

Magento 2 Deadlock Retry Module

In Mysql.php line 589:    SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to      get lock; try restarting transaction, query was: DELETE FROM `cron_schedule     ` WHERE (status = 'missed') AND (job_code in ('jobs_ecommerce', 'ebizm     arts_webhooks', 'jobs_clean_webhooks', 'jobs_clean_batches')) AND      (created_at < '2019-04-18 04:06:05')                                           In Pdo.php line 235:    SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to      get lock; try restarting transaction, query was: DELETE FROM `cron_schedule     ` WHERE (status = 'missed') AND (job_code in ('jobs_ecommerce', 'ebizm     arts_webhooks', 'jobs_clean_webhooks', 'jobs_clean_batches')) AND      (created_at < '2019-04-18 04:06:05')                                           In Pdo.php line 228:    SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to      get lock; try restarting transaction                                            cron:run [--group GROUP] [--bootstrap BOOTSTRAP] 

Magento 2.3.1 Vanilla Cron Error? Serialization failure: 1213 Deadlock found when trying to get lock

So we installed Magento 2.3.1 and some extensions. Nothing fancy. No data nothing. No errors until now.

Only every once per day we see the below error via our admin email. Can be any kind of job differs per day.

I am trying to understand why/how these jobs are leading to problems with cron if we arent really doing anything yet. This would appear a simple cron task to us.

How can we prevent this?

I dont believe truncating the tables is the solution as I have read somewhere … I mean the error would just re-occur some days later.

In Mysql.php line 589:    SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to      get lock; try restarting transaction, query was: DELETE FROM `cron_schedule     ` WHERE (status = 'missed') AND (job_code in ('the_job_code', 'ebizm     arts_webhooks', 'jobs_clean_webhooks', 'jobs_clean_batches')) AND      (created_at < '2019-04-18 04:06:05')                                          In Pdo.php line 235:    SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to      get lock; try restarting transaction, query was: DELETE FROM `cron_schedule     ` WHERE (status = 'missed') AND (job_code in ('the_job_code', 'ebizm     arts_webhooks', 'jobs_clean_webhooks', 'jobs_clean_batches')) AND      (created_at < '2019-04-18 04:06:05')                                          In Pdo.php line 228:    SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to      get lock; try restarting transaction                                            cron:run [--group GROUP] [--bootstrap BOOTSTRAP] 

Borgmatic cron job errors with python `ModuleNotFoundError`

I am trying to set up a daily cron job which backs up some files using borgmatic, but I keep getting the same error and have not been able to figure out how to fix it.

My borgmatic version:

$   borgmatic --version 1.3.0 

My /etc/cron.daily/borgmatic file:

#!/bin/bash MAILTO="tomeraberbach@gmail.com" PATH=$  PATH:/usr/local/bin PYTHONPATH=/home/tomeraberbach/.local/lib/python3.6/site-packages /usr/local/bin/borgmatic 

And its permissions:

$   ls -l /etc/cron.daily/borgmatic -rwxr-xr-x 1 root tomeraberbach 162 Apr  8 00:20 /etc/cron.daily/borgmatic* 

However, I keep getting the following error when the job runs:

/etc/cron.daily/borgmatic: Traceback (most recent call last):   File "/usr/local/bin/borgmatic", line 7, in <module>     from borgmatic.commands.borgmatic import main   File "/usr/local/lib/python3.6/dist-packages/borgmatic/commands/borgmatic.py", line 22, in <module>     from borgmatic.config import checks, collect, convert, validate   File "/usr/local/lib/python3.6/dist-packages/borgmatic/config/convert.py", line 3, in <module>     from ruamel import yaml ModuleNotFoundError: No module named 'ruamel' run-parts: /etc/cron.daily/borgmatic exited with return code 1 

This only happens in the cron job. Runnning borgmatic normally works fine.

Additionally, the ruamel package is definitely installed:

$   ls /home/tomeraberbach/.local/lib/python3.6/site-packages/ruamel yaml/ 

Any ideas why this is happening? I know cron runs in a different environment, but I am not sure how to fix this issue.

How to make external script inaccessible by browser and accessible by cron? Magento 2

I have made a few external php scripts to update quantity and tracking numbers,etc Right now, i’m putting them in magento root and set the permission to 640. However, it’s still accessible by the public and/or the browser. I would like to make it accessible by cron and the owner/group only.

Drush command to run cron won’t work in Crontab

I am attempting to run two Drush commands from my crontab:

# m h  dom mon dow   command */2 * * * * drush -r /path -l https://www.domain.com/ cron */2 * * * * drush -r /path -l https://www.domain.com/ -u civicron civicrm-api job.execute 

Both of these commands work when I run them manually on the server, however they do not appear to work through crontab, even though the log shows them running:

Apr 17 20:16:01 ip-000000000000 CRON[3736]: (ubuntu) CMD (drush -r /path -l https://www.domain.com/ -u civicron civicrm-api job.execute) Apr 17 20:16:01 ip-000000000000 CRON[3737]: (ubuntu) CMD (drush -r /path -l https://www.domain.com/ cron) 

Any suggestion as I cannot see why these would not be running?

Magento 2.3.0 custom cron job is not working

Magento 2 custom corn is not working in my custom module.

app/code/Namespace/ModuleName/etc/crontab.xml

<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_reminder_cronjob" instance="Namespace\Modulename\Cron\ReminderEmail" method="execute">         <schedule>* * * * *</schedule>     </job> </group> 

app/code/Namespace/Modulename/Cron/ReminderEmail.php

<?php namespace Namespace\Modulename\Cron;  use \Psr\Log\LoggerInterface;  class ReminderEmail {     /**     * Write to system.log     *     * @return void     */      public function execute()     {                 $  writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');         $  logger = new \Zend\Log\Logger();         $  logger->addWriter($  writer);         $  logger->info('Test cron worked successfully');     } } 

Something is missing or wrong in the code above. can anyone help me to solve out this?

I have already try below way.

  • HOW TO SET AND CONFIGURE CUSTOM CRON JOBS IN MAGENTO 2?
  • Configure a custom cron job and cron

Any help would be appreciated! Thanks.

OOP design of a constantly running CRON job for performance


Problem:

I’m attempting to redesign my initial script class called EQ, which takes 15-20 minutes to run using a CRON job and my only goal is making it faster for a single server web application.

Since the design was (incorrect), I created (a) smaller classes; (b) a key class; and (c) one interface:

Key Class: EQ

class EQ implements ConstEQ {      public static function getEQmethodA()     {     }      public static function getEQmethodB()     {     }      ...  } 

Interface

A large list of constants goes here, which later, part of listed constants should be dynamically changed with other scripts:

interface ConstEQ {      /**      *      * @var numbers library      */     const COEF_1 = 1.10; // A level (1) coefficient for testing     const COEF_2 = 2.20; // A level (2) coefficient for testing     const COEF_3 = 3.30; // A level (3) coefficient for testing     const COEF_4 = 4.40; // A level (4) coefficient for testing     const COEF_5 = 5.50; // A level (5) coefficient for testing     const COEF_6 = 6.60; // A level (6) coefficient for testing     const COEF_7 = 7.70; // A level (7) coefficient for testing     ...  } 

Smaller Classes

class A extends EQ implements ConstEQ {       public static function getCoefficientA()     {     }      public static function getCoefficientB()     {     }      ...      }   class B extends EQ implements ConstEQ {       public static function getEquationA()     {     }      public static function getEquationB()     {     }          ... }   class C extends EQ implements ConstEQ {       public static function getStatisticsA()     {     }      public static function getStatisticsB()     {     }          ...  } 

How do I redesign my codes for performance?


PS: Classes are large and cannot be added to the question due to character limitation and can be viewed in this GitHub directory.