@@ -686,47 +686,52 @@ Push.Configure = function(options) {
686
686
if ( isSendingNotification ) {
687
687
return ;
688
688
}
689
- // Set send fence
690
- isSendingNotification = true ;
691
-
692
- // var countSent = 0;
693
- var batchSize = options . sendBatchSize || 1 ;
694
-
695
- var now = + new Date ( ) ;
696
-
697
- // Find notifications that are not being or already sent
698
- var pendingNotifications = Push . notifications . find ( { $and : [
699
- // Message is not sent
700
- { sent : false } ,
701
- // And not being sent by other instances
702
- { sending : { $lt : now } } ,
703
- // And not queued for future
704
- { $or : [
705
- { delayUntil : { $exists : false } } ,
706
- { delayUntil : { $lte : new Date ( ) } }
707
- ]
708
- }
709
- ] } , {
710
- // Sort by created date
711
- sort : { createdAt : 1 } ,
712
- limit : batchSize
713
- } ) ;
714
689
715
- pendingNotifications . forEach ( function ( notification ) {
716
- try {
717
- sendNotification ( notification ) ;
718
- } catch ( error ) {
719
- if ( typeof Push . Log === 'function' ) {
720
- Push . Log ( 'Push: Could not send notification id: "' + notification . _id + '", Error:' , error . message ) ;
721
- }
722
- if ( Push . debug ) {
723
- console . log ( 'Push: Could not send notification id: "' + notification . _id + '", Error: ' + error . message ) ;
690
+ try {
691
+
692
+ // Set send fence
693
+ isSendingNotification = true ;
694
+
695
+ // var countSent = 0;
696
+ var batchSize = options . sendBatchSize || 1 ;
697
+
698
+ var now = + new Date ( ) ;
699
+
700
+ // Find notifications that are not being or already sent
701
+ var pendingNotifications = Push . notifications . find ( { $and : [
702
+ // Message is not sent
703
+ { sent : false } ,
704
+ // And not being sent by other instances
705
+ { sending : { $lt : now } } ,
706
+ // And not queued for future
707
+ { $or : [
708
+ { delayUntil : { $exists : false } } ,
709
+ { delayUntil : { $lte : new Date ( ) } }
710
+ ]
711
+ }
712
+ ] } , {
713
+ // Sort by created date
714
+ sort : { createdAt : 1 } ,
715
+ limit : batchSize
716
+ } ) ;
717
+
718
+ pendingNotifications . forEach ( function ( notification ) {
719
+ try {
720
+ sendNotification ( notification ) ;
721
+ } catch ( error ) {
722
+ if ( typeof Push . Log === 'function' ) {
723
+ Push . Log ( 'Push: Could not send notification id: "' + notification . _id + '", Error:' , error . message ) ;
724
+ }
725
+ if ( Push . debug ) {
726
+ console . log ( 'Push: Could not send notification id: "' + notification . _id + '", Error: ' + error . message ) ;
727
+ }
724
728
}
725
- }
726
- } ) ; // EO forEach
729
+ } ) ; // EO forEach
730
+ } finally {
727
731
728
- // Remove the send fence
729
- isSendingNotification = false ;
732
+ // Remove the send fence
733
+ isSendingNotification = false ;
734
+ }
730
735
} , options . sendInterval || 15000 ) ; // Default every 15th sec
731
736
732
737
} else {
0 commit comments