feat(agent): add execution context recovery
This commit is contained in:
1 parent
e55dbe2acc
commit
0b6e1579ca
7 files changed
+381
-60
No files matched your search
@@ -877,21 +877,21 @@ pub async fn do_execute(
|
||||
let p = p.clone();
|
||||
let schema = schema.map(|s| s.to_string());
|
||||
let max_rows = options.max_rows;
|
||||
let query_timeout = query_timeout;
|
||||
drop(connections);
|
||||
if let Some(schema) = schema {
|
||||
wait_for_query_opt(
|
||||
db::postgres::execute_query_with_schema_and_max_rows_and_cancel(
|
||||
&p,
|
||||
&schema,
|
||||
sql,
|
||||
max_rows,
|
||||
cancel_token,
|
||||
query_timeout,
|
||||
db::postgres::execute_query_with_schema_and_max_rows(&p, &schema, sql, max_rows),
|
||||
)
|
||||
.await
|
||||
} else {
|
||||
wait_for_query_opt(
|
||||
cancel_token,
|
||||
query_timeout,
|
||||
db::postgres::execute_query_with_max_rows(&p, sql, max_rows),
|
||||
)
|
||||
.await
|
||||
db::postgres::execute_query_with_max_rows_and_cancel(&p, sql, max_rows, cancel_token, query_timeout)
|
||||
.await
|
||||
}
|
||||
}
|
||||
PoolKind::Sqlite(p) => {
|
||||
@@ -1024,21 +1024,39 @@ pub async fn do_execute(
|
||||
let max_rows = options.max_rows;
|
||||
let rpc_timeout = query_timeout;
|
||||
drop(connections);
|
||||
let result = wait_for_query_opt(cancel_token, query_timeout, async move {
|
||||
let mut client = client.lock().await;
|
||||
if is_canceled(&cancel_token) {
|
||||
return Err(canceled_error());
|
||||
}
|
||||
let cancel_for_agent = cancel_token.clone();
|
||||
let result = async move {
|
||||
let mut client = match cancel_for_agent.as_ref() {
|
||||
Some(token) => {
|
||||
tokio::select! {
|
||||
biased;
|
||||
_ = token.cancelled() => return Err(canceled_error()),
|
||||
guard = client.lock() => guard,
|
||||
}
|
||||
}
|
||||
None => client.lock().await,
|
||||
};
|
||||
if let Some(session_id) = options.result_session_id.as_deref() {
|
||||
let params = agent_fetch_query_page_params(session_id, options.page_size.unwrap_or(MAX_ROWS));
|
||||
client.fetch_query_page_with_timeout(params, rpc_timeout).await
|
||||
client.fetch_query_page_with_timeout_and_cancel(params, rpc_timeout, cancel_for_agent.clone()).await
|
||||
} else if options.page_size.is_some() {
|
||||
let params = agent_execute_query_page_params(&sql, database.as_deref(), schema.as_deref(), options);
|
||||
client.execute_query_page_with_timeout(params, rpc_timeout).await
|
||||
client
|
||||
.execute_query_page_with_timeout_and_cancel(params, rpc_timeout, cancel_for_agent.clone())
|
||||
.await
|
||||
} else {
|
||||
let params = agent_execute_query_params(&sql, database.as_deref(), schema.as_deref(), options);
|
||||
client.execute_query_with_timeout(params, rpc_timeout).await
|
||||
client.execute_query_with_timeout_and_cancel(params, rpc_timeout, cancel_for_agent.clone()).await
|
||||
}
|
||||
})
|
||||
}
|
||||
.await
|
||||
.map(|result| normalize_query_result_for_js(truncate_result_with_max_rows(result, max_rows)));
|
||||
if matches!(result.as_ref(), Err(err) if err == QUERY_CANCELED) {
|
||||
state.remove_pool_by_key(pool_key).await;
|
||||
}
|
||||
if matches!(result.as_ref(), Err(err) if should_discard_pool_after_error(pool_db_type, err)) {
|
||||
state.remove_pool_by_key(pool_key).await;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user