async fn write_alert(
	alert_data: AlertData,
	monitor_id: Id,
	database_pool: &sqlx::AnyPool,
) -> Result<()> {
	let mut db = match database_pool.begin().await {
		Ok(db) => db,
		Err(_) => {
			eprintln!("Oh no! Failed to write alert progress to DB");
			return Err(anyhow!("Database unavailable"));
		}
	};

	let data = serde_json::to_string(&alert_data)?;

	sqlx::query(
		"
		 insert into alerts
		 	(id, monitor_id, data, date)
		 values
		 	($1, $2, $3, $4)
		",
	)
	.bind(Id::generate().to_string())
	.bind(monitor_id.to_string())
	.bind(data)
	.execute(&mut db)
	.await?;
	db.commit().await?;
	Ok(())
}
/// Log the completion of an alert handling process
Log the completion of an alert handling process
Log the completion of an alert handling process
async fn write_alert(
	alert_data: AlertData,
	monitor_id: Id,
	database_pool: &sqlx::AnyPool,
) -> Result<()> {
	let mut db = match database_pool.begin().await {
		Ok(db) => db,
		Err(_) => {
			eprintln!("Oh no! Failed to write alert progress to DB");
			return Err(anyhow!("Database unavailable"));
		}
	};
	let data = serde_json::to_string(&alert_data)?;
	sqlx::query(
		"
		 insert into alerts
		 	(id, monitor_id, data, date)
		 values
		 	($1, $2, $3, $4)
		",
	)
	.bind(Id::generate().to_string())
	.bind(monitor_id.to_string())
	.bind(data)
	.execute(&mut db)
	.await?;
	db.commit().await?;
	Ok(())
}
async fn write_alert ( alert_data : AlertData , monitor_id : Id , database_pool : & sqlx :: AnyPool , ) -> Result < ( ) > { let mut db = match database_pool . begin ( ) . await { Ok ( db ) => db , Err ( _ ) => { eprintln ! ( " " ) ; return Err ( anyhow ! ( " " ) ) ; } } ; let data = serde_json :: to_string ( & alert_data ) ? ; sqlx :: query ( " " , ) . bind ( Id :: generate ( ) . to_string ( ) ) . bind ( monitor_id . to_string ( ) ) . bind ( data ) . execute ( & mut db ) . await ? ; db . commit ( ) . await ? ; Ok ( ( ) ) }
Log the completion of an alert handling process
Log the completion of an alert handling process
alert_data
AlertData
monitor_id
Id
database_pool
&sqlx::AnyPool
alert_data
AlertData
monitor_id
Id
database_pool
&sqlx::AnyPool