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

Conversation

jitendrapurohit
Copy link
Contributor

Overview

Add alert to display scheduled job errors

Before

Schedule job fails silently. Civi core doesn't provide an inbuilt option to notify admins.

From https://chat.civicrm.org/civicrm/pl/8wbq1y3j4tdeumnf1iuie44a5o

anyone else wondered about having Sch Reminder errors listed as problems in System Status? Just found a case where 5 months back 'somehow' a membership was given an End Date of 0000:00:00 and guess what. that stops renewal reminders being sent out. sheesh.

After

Alert displayed on the system status page. Eg

image

@civibot
Copy link

civibot bot commented Oct 7, 2021

(Standard links)

@civibot civibot bot added the master label Oct 7, 2021
@eileenmcnaughton
Copy link
Contributor

@jitendrapurohit style warning

@sunilpawar
Copy link
Contributor

i have built similar functionality using extension : https://github.com/Skvare/com.skvare.jobchecker

@eileenmcnaughton
Copy link
Contributor

@sunilpawar your extension looks nice & slightly more advanced than this. I think it's OK to have some functionality in core & an extension if people want more - I'm wondering what your thoughts are?

@sunilpawar
Copy link
Contributor

@sunilpawar your extension looks nice & slightly more advanced than this. I think it's OK to have some functionality in core & an extension if people want more - I'm wondering what your thoughts are?

@eileenmcnaughton
Actually i was in planing to publish this extension.
If extension configuration is useful then you can use it, so i do not need to publish the same functionality through extension.

@wmortada
Copy link
Contributor

@jitendrapurohit this sounds great! It would be a start in addressing the following two issues:

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.

@mlutfy
Copy link
Member

mlutfy commented Dec 10, 2021

@jitendrapurohit Unfortunately it's not quite right - please see: https://docs.civicrm.org/dev/en/latest/translation/#best-practices

For example:

  • $message = ts("<p>The following scheduled jobs failed on the last run:</p> - wrap just the string, not the HTML (when possible)
  • ts($message), - do not include variables in ts (unless it uses placeholders), but besides it is already translated a few lines above.

@jitendrapurohit
Copy link
Contributor Author

Thanks @mlutfy I've updated the usage in the latest commit 👍

<td>' . ts('%1', [1 => $job['name']]) . ' </td>
<td>' . ts('%1', [1 => $lastExecutionMessage]) . '</td>
<td>' . ts('%1', [1 => $job['last_run']]) . '</td>
<td>' . ts('<a href=\'%1\'>View Job Log</a>', [1 => $viewLogURL]) . '</td>
Copy link
Member

Choose a reason for hiding this comment

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

Can you do instead:

<td><a href="' . $viewLogURL . '"> . ts('View Job Log') . '</a></td>

This way it avoids adding a new string to translate (and HTML should be avoided when possible).

$ grep -r 'View Job Log'
CRM/Admin/Page/Job.php:          'name' => ts('View Job Log'),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated with the above suggestion 👍

if (!empty($lastExecutionMessage) && strpos($lastExecutionMessage, 'Failure') !== FALSE) {
$viewLogURL = CRM_Utils_System::url('civicrm/admin/joblog', "jid={$job['id']}&reset=1");
$html .= '<tr>
<td>' . ts('%1', [1 => $job['name']]) . ' </td>
Copy link
Member

@mlutfy mlutfy Dec 15, 2021

Choose a reason for hiding this comment

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

ts is not necessary here. Job names are not translatable (they are set/translated during the installation, in civicrm_data.xx_XX.mysql).

The other changes are good, so just these tiny 3 edits and we're done :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

$html .= '<tr>
<td>' . ts('%1', [1 => $job['name']]) . ' </td>
<td>' . ts('%1', [1 => $lastExecutionMessage]) . '</td>
<td>' . ts('%1', [1 => $job['last_run']]) . '</td>
Copy link
Member

Choose a reason for hiding this comment

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

ts not necessary for the above two lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed now. Thanks.

@mlutfy
Copy link
Member

mlutfy commented Dec 16, 2021

@jitendrapurohit Thank you!

Merging based on code review, feedback from other reviewers, and also r-run:

image

@mlutfy mlutfy merged commit f0b7645 into civicrm:master Dec 16, 2021
@demeritcowboy
Copy link
Contributor

I remember seeing this PR and not really paying attention because I always dealt with this issue another way, but after rolling out 5.46 I see this is a good thing™. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants