Log and output all error occured during last cron run

[MAILPOET-2017]
This commit is contained in:
Jan Jakeš
2019-04-30 16:55:29 +02:00
committed by M. Shull
parent 0fa5146146
commit 0a1b475ffd
2 changed files with 27 additions and 2 deletions

View File

@@ -10,6 +10,22 @@ const CronStatus = (props) => {
active: MailPoet.I18n.t('running'),
inactive: MailPoet.I18n.t('cronWaiting'),
};
const lastError = Array.isArray(status.last_error)
? (
<>
{
status.last_error.map(error => (
<div key={error.worker}>
{error.worker}
:
{' '}
<i>{error.message}</i>
</div>
))
}
</>
)
: status.last_error;
return (
<div>
<h2>{MailPoet.I18n.t('systemStatusCronStatusTitle')}</h2>
@@ -38,7 +54,7 @@ const CronStatus = (props) => {
},
{
key: MailPoet.I18n.t('lastSeenError'),
value: status.last_error || MailPoet.I18n.t('none'),
value: lastError || MailPoet.I18n.t('none'),
},
]}
/>

View File

@@ -25,14 +25,23 @@ class Daemon {
$settings_daemon_data['run_started_at'] = time();
CronHelper::saveDaemon($settings_daemon_data);
$errors = [];
foreach ($this->getWorkers() as $worker) {
try {
$worker->process();
} catch (\Exception $e) {
CronHelper::saveDaemonLastError($e->getMessage());
$worker_class_name_parts = explode('\\', get_class($worker));
$errors[] = [
'worker' => end($worker_class_name_parts),
'message' => $e->getMessage(),
];
}
}
if (!empty($errors)) {
CronHelper::saveDaemonLastError($errors);
}
// Log successful execution
CronHelper::saveDaemonRunCompleted(time());
}