async fn check_ongoing(id: Id, database_pool: &sqlx::AnyPool) -> Result<bool> {
	let mut db = match database_pool.begin().await {
		Ok(db) => db,
		Err(_) => {
			eprintln!("Oh no! Failed to read database!");
			return Err(anyhow!("Database unavailable"));
		}
	};
	let ten_minutes_in_seconds: i32 = 10 * 60;
	let now = time::OffsetDateTime::now_utc().unix_timestamp();
	let existing = sqlx::query(
		"
			select
				*
			from
				alerts
			where
				id = $1 and
				$2 - alerts.date < $3
		",
	)
	.bind(id.to_string())
	.bind(&now)
	.bind(&ten_minutes_in_seconds)
	.fetch_optional(&mut db)
	.await?;
	db.commit().await?;
	Ok(existing.is_some())
}
/// Read the DB to see if the given cadence is already in process
Read the DB to see if the given cadence is already in process
Read the DB to see if the given cadence is already in process
async fn check_ongoing(id: Id, database_pool: &sqlx::AnyPool) -> Result<bool> {
	let mut db = match database_pool.begin().await {
		Ok(db) => db,
		Err(_) => {
			eprintln!("Oh no! Failed to read database!");
			return Err(anyhow!("Database unavailable"));
		}
	};
	let ten_minutes_in_seconds: i32 = 10 * 60;
	let now = time::OffsetDateTime::now_utc().unix_timestamp();
	let existing = sqlx::query(
		"
			select
				*
			from
				alerts
			where
				id = $1 and
				$2 - alerts.date < $3
		",
	)
	.bind(id.to_string())
	.bind(&now)
	.bind(&ten_minutes_in_seconds)
	.fetch_optional(&mut db)
	.await?;
	db.commit().await?;
	Ok(existing.is_some())
}
async fn check_ongoing ( id : Id , database_pool : & sqlx :: AnyPool ) -> Result < bool > { let mut db = match database_pool . begin ( ) . await { Ok ( db ) => db , Err ( _ ) => { eprintln ! ( " " ) ; return Err ( anyhow ! ( " " ) ) ; } } ; let ten_minutes_in_seconds : i32 = 10 * 60 ; let now = time :: OffsetDateTime :: now_utc ( ) . unix_timestamp ( ) ; let existing = sqlx :: query ( " " , ) . bind ( id . to_string ( ) ) . bind ( & now ) . bind ( & ten_minutes_in_seconds ) . fetch_optional ( & mut db ) . await ? ; db . commit ( ) . await ? ; Ok ( existing . is_some ( ) ) }
Read the DB to see if the given cadence is already in process
Read the DB to see if the given cadence is already in process
id
Id
database_pool
&sqlx::AnyPool
id
Id
database_pool
&sqlx::AnyPool