use std::{convert::Infallible, future::ready};
use http::Request;
use http_body_util::combinators::BoxBody;
use hyper::{
Response,
body::{Bytes, Incoming},
};
use prosa::core::adaptor::Adaptor;
use tracing::warn;
use crate::proc::{FetchAction, FetcherError, FetcherProc};
pub trait FetcherAdaptor<M>: Adaptor
where
M: 'static
+ std::marker::Send
+ std::marker::Sync
+ std::marker::Sized
+ std::clone::Clone
+ std::fmt::Debug
+ prosa::core::msg::Tvf
+ std::default::Default,
{
fn new(proc: &FetcherProc<M>) -> Result<Self, FetcherError<M>>
where
Self: std::marker::Sized;
fn fetch(&mut self) -> Result<FetchAction<M>, FetcherError<M>>;
fn create_http_request(
&self,
request_builder: http::request::Builder,
) -> Result<Request<BoxBody<Bytes, Infallible>>, FetcherError<M>>;
fn process_http_response(
&mut self,
response: Result<Response<Incoming>, FetcherError<M>>,
) -> impl std::future::Future<Output = Result<FetchAction<M>, FetcherError<M>>> + Send {
if let Err(e) = response {
warn!("Wrong HTTP response: {:?}", e);
ready(Err(e))
} else {
ready(Ok(FetchAction::None))
}
}
fn process_service_response(
&mut self,
_response: prosa::core::msg::ResponseMsg<M>,
) -> Result<FetchAction<M>, FetcherError<M>> {
Ok(FetchAction::None)
}
fn process_service_error(
&self,
_error: prosa::core::msg::ErrorMsg<M>,
) -> Result<FetchAction<M>, FetcherError<M>> {
Ok(FetchAction::None)
}
fn end_active_period(&mut self) {}
}