Skip to content
Snippets Groups Projects
Commit 3ee2fb04 authored by Justus Dieckmann's avatar Justus Dieckmann
Browse files

Only notify for new errors every cron

parent c8f23136
Branches
No related tags found
No related merge requests found
...@@ -260,6 +260,7 @@ class process_manager { ...@@ -260,6 +260,7 @@ class process_manager {
$procerror = (object) clone $process; $procerror = (object) clone $process;
$procerror->errormessage = get_class($e) . ': ' . $e->getMessage(); $procerror->errormessage = get_class($e) . ': ' . $e->getMessage();
$procerror->errortrace = $e->getTraceAsString(); $procerror->errortrace = $e->getTraceAsString();
$procerror->errortime = time();
$m = ''; $m = '';
foreach ($e->getTrace() as $v) { foreach ($e->getTrace() as $v) {
$m .= $v['file'] . ':' . $v['line'] . '::'; $m .= $v['file'] . ':' . $v['line'] . '::';
...@@ -283,6 +284,7 @@ class process_manager { ...@@ -283,6 +284,7 @@ class process_manager {
unset($process->errormessage); unset($process->errormessage);
unset($process->errortrace); unset($process->errortrace);
unset($process->errorhash); unset($process->errorhash);
unset($process->errortime);
$DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true); $DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true);
$DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]); $DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]);
...@@ -301,6 +303,7 @@ class process_manager { ...@@ -301,6 +303,7 @@ class process_manager {
unset($process->errormessage); unset($process->errormessage);
unset($process->errortrace); unset($process->errortrace);
unset($process->errorhash); unset($process->errorhash);
unset($process->errortime);
$DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true); $DB->insert_record_raw('tool_lifecycle_process', $process, false, false, true);
$DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]); $DB->delete_records('tool_lifecycle_proc_error', ['id' => $process->id]);
......
...@@ -50,7 +50,16 @@ class lifecycle_error_notify_task extends \core\task\scheduled_task { ...@@ -50,7 +50,16 @@ class lifecycle_error_notify_task extends \core\task\scheduled_task {
public function execute() { public function execute() {
global $DB, $CFG; global $DB, $CFG;
$errorcount = $DB->count_records('tool_lifecycle_proc_error'); $lastrun = get_config('tool_lifecycle', 'adminerrornotifylastrun');
if (!$lastrun) {
$lastrun = 0;
}
$currenttime = time();
$errorcount = $DB->count_records_select('tool_lifecycle_proc_error', 'errortime > :lastrun', ['lastrun' => $lastrun]);
set_config('adminerrornotifylastrun', $currenttime, 'tool_lifecycle');
if (!$errorcount) { if (!$errorcount) {
return; return;
......
...@@ -157,6 +157,7 @@ ...@@ -157,6 +157,7 @@
<FIELD NAME="errormessage" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Message of the error"/> <FIELD NAME="errormessage" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="Message of the error"/>
<FIELD NAME="errortrace" TYPE="text" NOTNULL="true" SEQUENCE="false"/> <FIELD NAME="errortrace" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="errorhash" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Where the error occured in the form 'path/to/filename.php:line'"/> <FIELD NAME="errorhash" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Where the error occured in the form 'path/to/filename.php:line'"/>
<FIELD NAME="errortime" TYPE="int" LENGTH="11" NOTNULL="true" SEQUENCE="false" COMMENT="unix timestamp - time the error occured"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
......
...@@ -461,6 +461,7 @@ function xmldb_tool_lifecycle_upgrade($oldversion) { ...@@ -461,6 +461,7 @@ function xmldb_tool_lifecycle_upgrade($oldversion) {
$table->add_field('errormessage', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); $table->add_field('errormessage', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('errortrace', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null); $table->add_field('errortrace', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('errorhash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null); $table->add_field('errorhash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('errortime', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, null);
// Adding keys to table tool_lifecycle_proc_error. // Adding keys to table tool_lifecycle_proc_error.
$table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']); $table->add_key('primary', XMLDB_KEY_PRIMARY, ['id']);
......
...@@ -183,6 +183,6 @@ $string['forselected'] = 'Für alle ausgewählten Prozesse'; ...@@ -183,6 +183,6 @@ $string['forselected'] = 'Für alle ausgewählten Prozesse';
$string['noprocesserrors'] = 'Es gibt keine fehlerhaften Prozesse, die behandelt werden müssen!'; $string['noprocesserrors'] = 'Es gibt keine fehlerhaften Prozesse, die behandelt werden müssen!';
$string['lifecycle_error_notify_task'] = 'Benachrichtigt die Administratoren bei Fehlern in tool_lifecycle-Prozessen.'; $string['lifecycle_error_notify_task'] = 'Benachrichtigt die Administratoren bei Fehlern in tool_lifecycle-Prozessen.';
$string['notifyerrorsemailsubject'] = '{$a->amount} fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!'; $string['notifyerrorsemailsubject'] = '{$a->amount} neue fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!';
$string['notifyerrorsemailcontent'] = '{$a->amount} fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!' . "\n" . 'Bitte besuchen Sie {$a->url}.'; $string['notifyerrorsemailcontent'] = '{$a->amount} neue fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!' . "\n" . 'Bitte besuchen Sie {$a->url}.';
$string['notifyerrorsemailcontenthtml'] = '{$a->amount} fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!<br>Bitte besuchen Sie <a href="{$a->url}">die Übersichtsseite</a>.'; $string['notifyerrorsemailcontenthtml'] = '{$a->amount} neue fehlerhafte tool_lifecycle Prozesse warten darauf, behandelt zu werden!<br>Bitte besuchen Sie <a href="{$a->url}">die Übersichtsseite</a>.';
...@@ -219,6 +219,6 @@ $string['forselected'] = 'For all selected processes'; ...@@ -219,6 +219,6 @@ $string['forselected'] = 'For all selected processes';
$string['noprocesserrors'] = 'There are no process errors to handle!'; $string['noprocesserrors'] = 'There are no process errors to handle!';
$string['lifecycle_error_notify_task'] = 'Notify the admin upon errors in tool_lifecycle processes'; $string['lifecycle_error_notify_task'] = 'Notify the admin upon errors in tool_lifecycle processes';
$string['notifyerrorsemailsubject'] = 'There are {$a->amount} tool_lifecycle process errors waiting to be fixed!'; $string['notifyerrorsemailsubject'] = 'There are {$a->amount} new tool_lifecycle process errors waiting to be fixed!';
$string['notifyerrorsemailcontent'] = 'There are {$a->amount} tool_lifecycle process errors waiting to be fixed!' . "\n" . 'Please review them at {$a->url}.'; $string['notifyerrorsemailcontent'] = 'There are {$a->amount} new tool_lifecycle process errors waiting to be fixed!' . "\n" . 'Please review them at {$a->url}.';
$string['notifyerrorsemailcontenthtml'] = 'There are {$a->amount} tool_lifecycle process errors waiting to be fixed!<br>Please review them at the <a href="{$a->url}">error handling overview</a>.'; $string['notifyerrorsemailcontenthtml'] = 'There are {$a->amount} new tool_lifecycle process errors waiting to be fixed!<br>Please review them at the <a href="{$a->url}">error handling overview</a>.';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment