[1.0.x] Cron Fail Alert

Created on 9 August 2023, about 1 year ago
Updated 1 July 2024, 3 months ago

This module is a valuable tool for Drupal site administrators, ensuring they stay informed about the status of the cron jobs. This module also sends email notifications to administrators when the Drupal cron fails to run within a specified time frame. By promptly alerting administrators of cron failures, this module helps maintain the health and performance of Drupal websites.

The Cron Fail Alert module enhances Drupal site management by monitoring the cron job execution and notifying administrators when issues arise. The key features and steps to use the module are as follows:

  1. Install and Configure: After installing the module, navigate to the configuration settings. Set the frequency and tolerance for the cron check according to your needs.
  2. Specify Email Address: Provide an email address where notifications about cron failures should be sent. This ensures that the relevant administrators receive timely alerts.
  3. Save Configuration: Save the configuration settings, and the module will take care of the rest.

Manual reviews of other projects

Project link

https://www.drupal.org/project/cron_fail_alert

📌 Task
Status

Closed: won't fix

Component

module

Created by

🇮🇳India Hemangi Gokhale

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Hemangi Gokhale
  • 🇮🇳India vishal.kadam Mumbai

    Thank you for applying! Reviewers will review the project files, describing what needs to be changed.

    Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.

    To reviewers: Please read How to review security advisory coverage applications , What to cover in an application review , and Drupal.org security advisory coverage application workflow .

    While this application is open, only the user who opened the application can make commits to the project used for the application.

    Reviewers only describe what needs to be changed; they don't provide patches to fix what reported in a review.

  • Status changed to Needs work about 1 year ago
  • 🇮🇳India vishal.kadam Mumbai

    Fix phpcs issue.

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml cron_fail_alert/
    
    FILE: cron_fail_alert/src/EventSubscriber/CronFailAlertSubscriber.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     148 | WARNING | Only string literals should be passed to t() where possible
    --------------------------------------------------------------------------------
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India Hemangi Gokhale

    Oops! I didn't notice that 🤦‍♀️. Thanks for letting me know. I've fixed it and made some more improvements. This is now ready for another review now.

  • 🇮🇳India vishal.kadam Mumbai

    Rest looks fine to me.

    Let’s wait for other reviewers to take a look and if everything goes fine, you will get the role.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work about 1 year ago
  • 🇦🇺Australia elc

    Non-blocking comments

  • Status changed to Needs review about 1 year ago
  • 🇮🇳India Hemangi Gokhale

    @ELC, thanks a lot for your feedback. I've made the changes you suggested, and you can see them in this commit: link to commit.

    Here are the updates I've made:

    Changes to 'cron_fail_alert_mail' Function
    I've used the 't()' function to translate the subject in the 'cron_fail_alert_mail' function, which helps with language translation.

    Fix for 'CronFailAlertSubscriber::cronStatusCheck()'
    Instead of using string translation, I'm now using FormattableMarkup because my string is combined with other parts. You can find more details here: link to FormattableMarkup.

    Additionally, I've done the following improvements:

    • Reorganized the logic and structure of the code to make it easier to read.
    • Made changes to comments and code to make everything clearer.
    • Renamed the cronStatusCheck() method to checkCronStatus() for better understanding.
    • Changed the name of the method cronFailAlertSendEmail() to sendCronFailAlertEmail() to make it consistent and clear.
    • Improved the naming of variables.

    Regarding the following points:

    The value of cron_fail_alert_last_check_timestamp is never updated if cron has never failed, from cronStatusCheck() doing "Return FALSE if cron has not failed". This means that if everything is working fine, the timestamp is not stepped, and every page load will be checking to see if cron has failed, which does not seem to be the point of the code to avoid running the full check on every request.

    • The line of code found at this link is always set to "false" during its initial execution. This occurs when the "checkCronStatus" process is carried out.
    • This specific line ensures that we adhere to the frequency limit set by the administrator, as described in this link.
    • If this limit is surpassed, we proceed to send an email and also update the value of the "cron_fail_alert.last_check_timestamp" state.

    The same outcome happens if the site fails to send the email - when this happens, the full check and attempt to send the email will happen on every page request. I would imagine both of these has the potential to slow down a site significantly.

    • After successfully sending the email, the value of cron_fail_alert.last_check_timestamp will get updated.
    • The same line of code (link to line) ensures that we only proceed if enough time has passed since the last check.
    • As a result, no more emails will be sent until that specific point in time.

    Feel free to let me know if you have any further questions or suggestions.

  • Status changed to Needs work about 1 year ago
  • 🇦🇺Australia elc

    Use of t() is implicitly deprecated, but not labelled as such. D10 t() docs states . Use of t() is still supported, but is no longer recommended since D8. Not a blocking issue now.

    The issue with setting the timestamp only when TRUE is returned from checkCronStatus() still exists, however this is more debugging than reviewing and I shouldn't really be doing it. This is it. It appears there is actually a new bug in this too.
    The value of cron_fail_alert.last_check_timestamp should be set regardless of the return value as the full expensive check has been done and does not wish to run the run again for at least $frequency. By not setting it, every page request will check to see if cron has failed until the time that cron does in fact fail AND the mail succeeds - neither of these outcomes is guaranteed. Only then will timestamp be updated and it will have a break for 15 minutes (by default).
    eg. Input initial values into the code

    • On every request .. event listener of KernelEvents::RESPONSE
    • $frequency = 15 (default)
    • $lastCheckTimestamp = 0 (module first installed, and/or cron never failed)
    • $minutesSinceLastCheck = (1692199541 - 0) / 60 = 28203325
    • ($minutesSinceLastCheck < $frequency) = (28203325 < 15) == FALSE
    • $lastCron = 1692199500
    • $minutesAgo = (1692199541 - 1692199500) / 60 = 0
    • $tolerance = 20 (default)
    • (!($minutesAgo >= $tolerance)) = (!(0 >= 20)) == TRUE
    • return FALSE
    • cron_fail_alert.last_check_timestamp NOT set
    • Next page request does the exact same thing

    Try it with cron_fail_alert.last_check_timestamp is set to 1692195900, it will do exactly the same thing.
    It may be detrimental to a site, this is not a blocking issue.

    For the subject on the email, I'd argue that it should be using TranslatableMarkup instead of FormattableMarkup - the comment you linked here, plus the 2 lines before it, state that because there is translation needed in the string being built, it should use TranslatableMarkup. The string is not just being concatenated, it contains english text in need of translation.

    As it stands the text "on Site" would not be translated.

    The only item pushing this to "Needs Work" is that string not being translated. Otherwise, despite the other notes, you're RTBC.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    I am removing the PAreview: review bonus tag, as per Review bonus , since a review has been already done.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    I am changing priority as per Issue priorities .

  • Status changed to Closed: won't fix 3 months ago
  • 🇮🇳India rushiraval

    This thread has been idle, in the needs work state with no activity for several months. Therefore, I am assuming that you are no longer pursuing this application, and I marked it as Closed (won't fix).

    If this is incorrect, and you are still pursuing this application, then please feel free to re-open it and set the issue status to Needs work or Needs review, depending on the current status of your code.

Production build 0.71.5 2024