Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add system status warning to display scheduled job failures #21762

Merged
merged 2 commits into from
Dec 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions CRM/Utils/Check/Component/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,51 @@ public function checkExtensions() {
return $messages;
}

/**
* @return CRM_Utils_Check_Message[]
*/
public function checkScheduledJobLogErrors() {
$jobs = civicrm_api3('Job', 'get', [
'sequential' => 1,
'return' => ["id", "name", "last_run"],
'is_active' => 1,
'options' => ['limit' => 0],
]);
$html = '';
foreach ($jobs['values'] as $job) {
$lastExecutionMessage = civicrm_api3('JobLog', 'get', [
'sequential' => 1,
'return' => ["description"],
'job_id' => $job['id'],
'options' => ['sort' => "id desc", 'limit' => 1],
])['values'][0]['description'] ?? NULL;
if (!empty($lastExecutionMessage) && strpos($lastExecutionMessage, 'Failure') !== FALSE) {
$viewLogURL = CRM_Utils_System::url('civicrm/admin/joblog', "jid={$job['id']}&reset=1");
$html .= "<tr><td>{$job['name']} </td><td>{$lastExecutionMessage}</td><td>{$job['last_run']}</td><td> <a href='{$viewLogURL}'>View Job Log</a></td></tr>";
}
}
if (empty($html)) {
return [];
}

$message = "<p>The following scheduled jobs failed on the last run:</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap the strings in ts() ? (this line, and other lines around it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late update @mlutfy. I've added the ts() now. Thanks.

<p><table><thead><tr><th>Job</th><th>Message</th><th>Date</th><th></th>
</tr></thead><tbody>
$html
</tbody></table></p>
";

$msg = new CRM_Utils_Check_Message(
__FUNCTION__,
ts($message),
ts('Scheduled Job Failures'),
\Psr\Log\LogLevel::WARNING,
'fa-server'
);
$messages[] = $msg;
return $messages;
}

/**
* Checks if there are pending extension upgrades.
*
Expand Down