mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-23 01:16:30 +00:00
* Prewarmer * hmm * Tests * default * fix test * Correct configuration * Added minimal config example * remove connect_timeout
29 lines
647 B
Rust
29 lines
647 B
Rust
//! Prewarm new connections before giving them to the client.
|
|
use crate::{errors::Error, server::Server};
|
|
use log::info;
|
|
|
|
pub struct Prewarmer<'a> {
|
|
pub enabled: bool,
|
|
pub server: &'a mut Server,
|
|
pub queries: &'a Vec<String>,
|
|
}
|
|
|
|
impl<'a> Prewarmer<'a> {
|
|
pub async fn run(&mut self) -> Result<(), Error> {
|
|
if !self.enabled {
|
|
return Ok(());
|
|
}
|
|
|
|
for query in self.queries {
|
|
info!(
|
|
"{} Prewarning with query: `{}`",
|
|
self.server.address(),
|
|
query
|
|
);
|
|
self.server.query(&query).await?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
}
|