Skip to content

Commit 215968f

Browse files
more generic cancellation handling (#192)
* more generic cancellation handling * pr feedback
1 parent a0b1826 commit 215968f

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/database/mysql.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ impl Database for MySqlDriver<'_> {
8181
if let Some(pid) = self.querying_pid.take() {
8282
let result = sqlx::raw_sql(&format!("KILL {pid}")).execute(&*self.pool.clone().unwrap()).await;
8383
let msg = match result {
84-
Ok(_) => "successfully killed".to_string(),
85-
Err(e) => format!("failed to kill: {e:?}"),
84+
Ok(_) => "Successfully killed".to_string(),
85+
Err(e) => format!("Failed to kill: {e:?}"),
8686
};
8787
log::info!("Tried to cancel backend process with PID {pid}: {msg} ");
8888
}

src/database/postgresql.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,23 @@ impl Database for PostgresDriver<'_> {
8383
_ => {},
8484
};
8585
if let Some(pid) = self.querying_pid.take() {
86-
let success = sqlx::raw_sql(&format!("SELECT pg_cancel_backend({pid})"))
87-
.fetch_one(&*self.pool.clone().unwrap())
88-
.await?
89-
.get::<bool, _>(0);
86+
let result =
87+
sqlx::raw_sql(&format!("SELECT pg_cancel_backend({pid})")).fetch_one(&*self.pool.clone().unwrap()).await;
88+
let msg = match &result {
89+
Ok(_) => "Successfully killed".to_string(),
90+
Err(e) => format!("Failed to kill: {e:?}"),
91+
};
92+
93+
let success = result.as_ref().is_ok_and(|r| r.try_get::<bool, _>(0).unwrap_or(false));
94+
let status_string =
95+
result.map_or("ERROR".to_string(), |r| r.try_get_unchecked::<String, _>(0).unwrap_or("ERROR".to_string()));
96+
9097
if !success {
91-
log::warn!("Failed to cancel backend process with PID {pid}");
98+
log::warn!("Unexpected response when cancelling backend process with PID {pid}: {msg}");
99+
log::warn!("Status: {status_string}");
92100
} else {
93-
log::info!("Cancelled backend process with PID {pid}");
101+
log::info!("Tried to cancel backend process with PID {pid}: {msg}");
102+
log::info!("Status: {status_string}");
94103
}
95104
}
96105
self.querying_conn = None;

0 commit comments

Comments
 (0)