fix(runtime): replace Handle::current().block_on() with std:🧵:spawn in transfer_to_human
Some checks failed
BotServer CI/CD / build (push) Failing after 1m18s
Some checks failed
BotServer CI/CD / build (push) Failing after 1m18s
- Handle::current().block_on() panics when called from within a runtime
- replaced all 5 occurrences with std:🧵:spawn + mpsc::channel
- matches the pattern already used across other keyword files
This commit is contained in:
parent
f2f81415e4
commit
3f94d23e1f
1 changed files with 120 additions and 75 deletions
|
|
@ -498,8 +498,13 @@ pub fn register_transfer_to_human_keyword(
|
|||
let state = state_clone.clone();
|
||||
let session = user_clone.clone();
|
||||
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let result = rt.block_on(async {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build();
|
||||
let result = match rt {
|
||||
Ok(rt) => rt.block_on(async {
|
||||
execute_transfer(
|
||||
state,
|
||||
&session,
|
||||
|
|
@ -512,8 +517,12 @@ pub fn register_transfer_to_human_keyword(
|
|||
},
|
||||
)
|
||||
.await
|
||||
}),
|
||||
Err(e) => Err(anyhow::anyhow!("Failed to create runtime: {}", e)),
|
||||
};
|
||||
let _ = tx.send(result);
|
||||
});
|
||||
|
||||
let result = rx.recv().unwrap_or_else(|e| Err(anyhow::anyhow!("Channel error: {}", e)));
|
||||
result.to_dynamic()
|
||||
});
|
||||
|
||||
|
|
@ -524,8 +533,13 @@ pub fn register_transfer_to_human_keyword(
|
|||
let session = user_clone.clone();
|
||||
let name_str = name.to_string();
|
||||
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let result = rt.block_on(async {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build();
|
||||
let result = match rt {
|
||||
Ok(rt) => rt.block_on(async {
|
||||
execute_transfer(
|
||||
state,
|
||||
&session,
|
||||
|
|
@ -538,8 +552,12 @@ pub fn register_transfer_to_human_keyword(
|
|||
},
|
||||
)
|
||||
.await
|
||||
}),
|
||||
Err(e) => Err(anyhow::anyhow!("Failed to create runtime: {}", e)),
|
||||
};
|
||||
let _ = tx.send(result);
|
||||
});
|
||||
|
||||
let result = rx.recv().unwrap_or_else(|e| Err(anyhow::anyhow!("Channel error: {}", e)));
|
||||
result.to_dynamic()
|
||||
});
|
||||
|
||||
|
|
@ -553,8 +571,13 @@ pub fn register_transfer_to_human_keyword(
|
|||
let dept = department.to_string();
|
||||
let prio = priority.to_string();
|
||||
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let result = rt.block_on(async {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build();
|
||||
let result = match rt {
|
||||
Ok(rt) => rt.block_on(async {
|
||||
execute_transfer(
|
||||
state,
|
||||
&session,
|
||||
|
|
@ -567,8 +590,12 @@ pub fn register_transfer_to_human_keyword(
|
|||
},
|
||||
)
|
||||
.await
|
||||
}),
|
||||
Err(e) => Err(anyhow::anyhow!("Failed to create runtime: {}", e)),
|
||||
};
|
||||
let _ = tx.send(result);
|
||||
});
|
||||
|
||||
let result = rx.recv().unwrap_or_else(|e| Err(anyhow::anyhow!("Channel error: {}", e)));
|
||||
result.to_dynamic()
|
||||
},
|
||||
);
|
||||
|
|
@ -584,8 +611,13 @@ pub fn register_transfer_to_human_keyword(
|
|||
let prio = priority.to_string();
|
||||
let rsn = reason.to_string();
|
||||
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let result = rt.block_on(async {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build();
|
||||
let result = match rt {
|
||||
Ok(rt) => rt.block_on(async {
|
||||
execute_transfer(
|
||||
state,
|
||||
&session,
|
||||
|
|
@ -598,8 +630,12 @@ pub fn register_transfer_to_human_keyword(
|
|||
},
|
||||
)
|
||||
.await
|
||||
}),
|
||||
Err(e) => Err(anyhow::anyhow!("Failed to create runtime: {}", e)),
|
||||
};
|
||||
let _ = tx.send(result);
|
||||
});
|
||||
|
||||
let result = rx.recv().unwrap_or_else(|e| Err(anyhow::anyhow!("Channel error: {}", e)));
|
||||
result.to_dynamic()
|
||||
},
|
||||
);
|
||||
|
|
@ -626,8 +662,13 @@ pub fn register_transfer_to_human_keyword(
|
|||
.get("context")
|
||||
.and_then(|v| v.clone().try_cast::<String>());
|
||||
|
||||
let rt = tokio::runtime::Handle::current();
|
||||
let result = rt.block_on(async {
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
std::thread::spawn(move || {
|
||||
let rt = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build();
|
||||
let result = match rt {
|
||||
Ok(rt) => rt.block_on(async {
|
||||
execute_transfer(
|
||||
state,
|
||||
&session,
|
||||
|
|
@ -640,8 +681,12 @@ pub fn register_transfer_to_human_keyword(
|
|||
},
|
||||
)
|
||||
.await
|
||||
}),
|
||||
Err(e) => Err(anyhow::anyhow!("Failed to create runtime: {}", e)),
|
||||
};
|
||||
let _ = tx.send(result);
|
||||
});
|
||||
|
||||
let result = rx.recv().unwrap_or_else(|e| Err(anyhow::anyhow!("Channel error: {}", e)));
|
||||
result.to_dynamic()
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue