Break notify loop on error
This commit is contained in:
		
							parent
							
								
									19857a77f1
								
							
						
					
					
						commit
						8fb810b5bf
					
				
					 1 changed files with 25 additions and 26 deletions
				
			
		|  | @ -6,10 +6,7 @@ use crate::{ | ||||||
| use activitystreams::primitives::XsdAnyUri; | use activitystreams::primitives::XsdAnyUri; | ||||||
| use actix::clock::{delay_for, Duration}; | use actix::clock::{delay_for, Duration}; | ||||||
| use bb8_postgres::tokio_postgres::{tls::NoTls, AsyncMessage, Config}; | use bb8_postgres::tokio_postgres::{tls::NoTls, AsyncMessage, Config}; | ||||||
| use futures::{ | use futures::stream::{poll_fn, StreamExt}; | ||||||
|     future::ready, |  | ||||||
|     stream::{poll_fn, StreamExt}, |  | ||||||
| }; |  | ||||||
| use log::{debug, error, warn}; | use log::{debug, error, warn}; | ||||||
| use std::{collections::HashMap, sync::Arc}; | use std::{collections::HashMap, sync::Arc}; | ||||||
| use uuid::Uuid; | use uuid::Uuid; | ||||||
|  | @ -68,29 +65,31 @@ impl Notifier { | ||||||
|                     } |                     } | ||||||
|                 }); |                 }); | ||||||
| 
 | 
 | ||||||
|                 let mut stream = poll_fn(move |cx| conn.poll_message(cx)).filter_map(|m| match m { |                 let mut stream = poll_fn(move |cx| conn.poll_message(cx)); | ||||||
|                     Ok(AsyncMessage::Notification(n)) => { |  | ||||||
|                         debug!("Handling Notification, {:?}", n); |  | ||||||
|                         ready(Some(n)) |  | ||||||
|                     } |  | ||||||
|                     Ok(AsyncMessage::Notice(e)) => { |  | ||||||
|                         debug!("Handling Notice, {:?}", e); |  | ||||||
|                         ready(None) |  | ||||||
|                     } |  | ||||||
|                     Err(e) => { |  | ||||||
|                         debug!("Handling Error, {:?}", e); |  | ||||||
|                         ready(None) |  | ||||||
|                     } |  | ||||||
|                     _ => { |  | ||||||
|                         debug!("Handling rest"); |  | ||||||
|                         ready(None) |  | ||||||
|                     } |  | ||||||
|                 }); |  | ||||||
| 
 | 
 | ||||||
|                 while let Some(n) = stream.next().await { |                 loop { | ||||||
|                     if let Some(v) = listeners.get(n.channel()) { |                     match stream.next().await { | ||||||
|                         for l in v { |                         Some(Ok(AsyncMessage::Notification(n))) => { | ||||||
|                             l.execute(n.payload()); |                             debug!("Handling Notification, {:?}", n); | ||||||
|  |                             if let Some(v) = listeners.get(n.channel()) { | ||||||
|  |                                 for l in v { | ||||||
|  |                                     l.execute(n.payload()); | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                         Some(Ok(AsyncMessage::Notice(e))) => { | ||||||
|  |                             debug!("Handling Notice, {:?}", e); | ||||||
|  |                         } | ||||||
|  |                         Some(Ok(_)) => { | ||||||
|  |                             debug!("Handling rest"); | ||||||
|  |                         } | ||||||
|  |                         Some(Err(e)) => { | ||||||
|  |                             debug!("Breaking loop due to error Error, {:?}", e); | ||||||
|  |                             break; | ||||||
|  |                         } | ||||||
|  |                         None => { | ||||||
|  |                             debug!("End of stream, breaking loop"); | ||||||
|  |                             break; | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue