Bsitu has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/59764


Change subject: Add execption to email job so error will be tracked
......................................................................

Add execption to email job so error will be tracked

Change-Id: I59ad29ddcf961f4d5582095b04eb77f616bc40c0
---
M includes/EmailBundler.php
M jobs/NotificationEmailBundleJob.php
2 files changed, 22 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Echo 
refs/changes/64/59764/1

diff --git a/includes/EmailBundler.php b/includes/EmailBundler.php
index 7b96cd6..2b431db 100644
--- a/includes/EmailBundler.php
+++ b/includes/EmailBundler.php
@@ -101,7 +101,7 @@
                // send instant single notification email if there is no base 
event in the batch queue
                // and the email is ready to send, otherwiase, add the email to 
batch and schedule
                // a delayed job
-               if ( !$this->baseEvent &&  $this->shouldSendEmailNow() ) {
+               if ( !$this->baseEvent && $this->shouldSendEmailNow() ) {
                        $this->timestamp = wfTimestampNow();
                        $this->updateEmailMetadata();
                        return false;
@@ -211,24 +211,23 @@
         * Main function for processinig bundle email
         */
        public function processBundleEmail() {
-               // User has switched to email digest, should not send any 
bundle email
-               // and should not schedule any bundle job, the daily cron will 
handle
-               // events left in the queue
-               if ( intval( $this->mUser->getOption( 'echo-email-frequency' ) 
) > 0 ) {
-                       return;
+               $emailSetting = intval( $this->mUser->getOption( 
'echo-email-frequency' ) );
+               
+               // User has switched to email digest or decided not to receive 
email,
+               // the daily cron will handle events left in the queue
+               if ( $emailSetting != 0 ) {
+                       throw new MWException( "User has swithched to email 
digest/no email option!" );
                }
 
-               $this->retrieveLastEmailTimestamp();
-
-               // if there is nothing in the queue, do not schedule a job or
-               // update timestamp so next email would be just an instant email
+               // If there is nothing in the queue, do not update timestamp so 
next
+               // email would be just an instant email
                if ( $this->retrieveBaseEvent() ) {
                        $this->timestamp = wfTimestampNow();
                        $this->updateEmailMetadata();
                        $this->sendEmail();
-                       // for testing purpose, comment out the line below so 
events are kept
                        $this->clearProcessedEvent();
-                       $this->pushToJobQueue( $this->emailInterval );
+               } else {
+                       throw new MWException( "There is no bundle notification 
to process!" );         
                }
        }
 
@@ -238,10 +237,8 @@
        protected function sendEmail() {
                $content = $this->generateEmailContent();
 
-               // Error has occurred
-               // @Todo more error handling
                if ( !isset( $content['subject'] ) || !isset( $content['body'] 
) ) {
-                       return;
+                       throw new MWException( "Fail to create create bundle 
email subject and body!" );
                }
 
                global $wgPasswordSender, $wgPasswordSenderName;
diff --git a/jobs/NotificationEmailBundleJob.php 
b/jobs/NotificationEmailBundleJob.php
index 22deebe..fe498d4 100644
--- a/jobs/NotificationEmailBundleJob.php
+++ b/jobs/NotificationEmailBundleJob.php
@@ -2,7 +2,7 @@
 
 class MWEchoNotificationEmailBundleJob extends Job {
        function __construct( $title, $params ) {
-               parent::__construct( 'MWEchoNotificationEmailBundleJob', 
$title, $params );
+               parent::__construct( __CLASS__, $title, $params );
                // If there is already a job with the same params, this job 
will be ignored
                // for example, if there is a page link bundle notification job 
for article A
                // created by user B, any subsequent jobs with the same data 
will be ignored
@@ -10,15 +10,17 @@
        }
 
        function run() {
-               $user = User::newFromId( $this->params['user_id'] );
-               if ( $user ) {
-                       $bundle = MWEchoEmailBundler::newFromUserHash( $user, 
$this->params['bundle_hash'] );
-                       if ( $bundle ) {
-                               $bundle->processBundleEmail();
-                       }
+               $bundle = MWEchoEmailBundler::newFromUserHash(
+                       User::newFromId( $this->params['user_id'] ),
+                       $this->params['bundle_hash']
+               );
+
+               if ( $bundle ) {
+                       $bundle->processBundleEmail();
                } else {
-                       //@Todo: delete notifications for this user_id
+                       throw new MWException( 'Fail to create bundle object 
for: user_id:' . $this->params['user_id'] . ', bundle_hash: ' . 
$this->params['bundle_hash'] );    
                }
+
                return true;
        }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/59764
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I59ad29ddcf961f4d5582095b04eb77f616bc40c0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Echo
Gerrit-Branch: master
Gerrit-Owner: Bsitu <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to