Jump to content

Send Notify Email About General Blesta's Cron Task Locked Or Stalled


Recommended Posts

Posted

Attached to this post, a poor man's cron script to check "health" of Blesta cron

 

Basically it's check in Blesta log being  in Blesta database & table log_cron

what is the max of end_date when `run_id` ='0'

 

run_id` ='0  in table log_cron

is matching to such Blesta cron output: "Attempting to run all tasks for ? XXX-COMPANY ? XXX-COMPANY.. All tasks have been completed."

 

so this cron script definite an acceptable last cron end_date ($Accepted_last_end_date) from time now, it's (timeNow -30mins) but you can change it as explained in bellow instruction, so if Blesta  end_date in table log_cron was older(inferior) than this $Accepted_last_end_date, you will receive an email (by smtp), and no more email will be sent until Blesta cron back to normal (this to prevent you to received a lot of warning email in your email box....)

-------------------

 

Require Pear & Pear Mail -( ever installed by default on most servers).

in console, check if pear is there, type:

pear version

 

 

install on debian:

---------------------

apt-get install php-pearl

pear install mail

pear install Net_SMTP

pear install Auth_SASL

pear install mail_mime

 

----------------
optional, require php cli (php5-cli) , for testing & see echo messages.


---------------
Decompress zip archive and place "check_blesta_cron" dir at one level above of your public_html dir ,

example, if you have path:
/home/YOUR-USER/public_html

place "check_blesta_cron" dir here:
/home/YOUR-USER/

--------------
Be aware that putting "check_blesta_cron" dir inside "public_html" is NOT SECURE.
If you want to do it, for doing WEB CRON, create a directory protected by password.
--------------



1/ "open_custom_blesta_db_connection.php" file & at top from line 5 to 8:  fill your Blesta database connection details


2/ "CRON_check_blesta_cron.php" :

 

- make time zone definited at line 7 be same as time zone chosen in Blesta admin area & menu: /settings/company/general/localization/

 - check/fill from line 103 to 115 , with your email address &  smtp parameters

- for TESTING if the sending of email work, read test instruction at line 64


3/
run "CRON_check_blesta_cron.php" :

3a/
- if you have console (command line access) use php CLI in console, to run test, type:

cd /PATH-TO/check_blesta_cron/
php CRON_check_blesta_cron.php

4/

For create a recurrent run (cronjob)

4a/
- use crontab & in console, type (if your user is not root just change root to your-user):

crontab -u root -e

Next ad this line in crontab:

*/15 * * * * php /PATH-TO/check_blesta_cron/CRON_check_blesta_cron.php

 

OR

 

4b/

create the cron job using your server control panel menu

 

 

N.B.: Depending of your OS, use:

 

*/15 * * * * php /PATH-TO/CRON_check_blesta_cron.php

 

OR

 

*/15 * * * * /usr/bin/php /PATH-TO/CRON_check_blesta_cron.php

-----------------------------------
So the this cron will be runing every 15mins & will check that last Blesta's cron was not more old that 30mins from date-time-now.

Please, read line 10 in CRON_check_blesta_cron.php if you want modify this value.


When you are ready to use this script in PRODUCTION, Please read instruction at line 66 in CRON_check_blesta_cron.php file  

 

 

HAPPY CRON!




 

check_blesta_cron.zip

Posted

Thxs, I updated my above instruction at step  2/ , in case you are not using UTC time at your Blesta admin area & menu: /settings/company/general/localization/

 

 

There could be an improvement for later, in the condition the blesta cron is found "not ok", & after send the warning email, we could add some cleaning or check in the Blesta tables "log_cron" & "cron_task_runs", and followed by one webcron request, as it's seem the Blesta webcron or a manual cron request from blesta interface is able to restart "locked/frozen" cron process, if some "cleaning have been done before in the db or if the 6 hours from Blesta cron script have expired, I would prefer my script do also the cleaning VS waiting 6 hours.

Posted

The 6 hours lock from Blesta can be found here,

Line 1909 in : /app/controllers/cron.php :
-----------
if (strtotime($last_run->start_date) < strtotime(date("c") . "-6 hours"))
---------

so it's does make sense to lock still runing cron task, but what will be the chance they end if there are not done in a couple of mins, I think, even in case of hundred of thousand of operations that should never be very long ?

6 hours is maybe excessive in my opinions, I will be more confortable with something like very max 1 hours or even 40 mins seem still to me very very fine.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...