Customize cron.php without replacing the stock file
I wanted to add functionality where I would be emailed if any of the cron jobs failed for any reason. I found in $sugar_config there is an option to override the cron class that is used to run scheduled jobs and normal cron related things. You can add it to the config_override.php file like this...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/***CONFIGURATOR***/ | |
$sugar_config['cron_class'] = 'CustomSugarCronJobs'; | |
/***CONFIGURATOR***/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); | |
//Include the original class | |
require_once 'include/SugarQueue/SugarCronJobs.php'; | |
/** | |
* CRON driver for job queue | |
* @api | |
*/ | |
class CustomSugarCronJobs extends SugarCronJobs | |
{ | |
/** | |
* What to do if one of the jobs failed | |
* @param SchedulersJob $job | |
*/ | |
protected function jobFailed($job = null) | |
{ | |
//Do my custom stuff | |
if(!empty($job)) { | |
$message = "Job {$job->id} ({$job->name}) failed in CRON run"; | |
//Email me the message | |
$GLOBALS['developerCommunication']->send($message, '', true); | |
} | |
//run the parent function | |
parent::jobFailed($job); | |
} | |
} |
Hello Kenneth,
ReplyDeleteCould you share the code of the $GLOBALS['developerCommunication'] class and how to put it as $GLOBAL?
Thank you.
Regards,
David.
Yes, its kinda crap at the moment, just a global function. Let me turn it into something a little better and I'll release it too. I should be able to do that tonight.
Delete