feat: 解决python虚拟环境问题
This commit is contained in:
@@ -25,6 +25,7 @@ use tokio_util::sync::CancellationToken;
|
||||
use crate::{
|
||||
error::ApiResult,
|
||||
process_job::ProcessJob,
|
||||
python_env::prepare_script_environment,
|
||||
runs::{
|
||||
model::{RunStatus, RunTrigger, TaskRunResponse},
|
||||
repository,
|
||||
@@ -291,18 +292,32 @@ impl TaskExecutor {
|
||||
match &task.action {
|
||||
TaskAction::Script {
|
||||
working_dir,
|
||||
venv,
|
||||
interpreter,
|
||||
script,
|
||||
args,
|
||||
env,
|
||||
} => {
|
||||
let mut command = Command::new(interpreter);
|
||||
command
|
||||
.arg(script)
|
||||
.args(args)
|
||||
.envs(env)
|
||||
.current_dir(working_dir);
|
||||
self.run_command(task, run_id, cancellation, command).await
|
||||
let prepared = match prepare_script_environment(
|
||||
working_dir,
|
||||
interpreter,
|
||||
venv.as_deref(),
|
||||
env,
|
||||
) {
|
||||
Ok(prepared) => prepared,
|
||||
Err(error) => {
|
||||
return failed_outcome(format!("准备 Python 运行环境失败: {error}"));
|
||||
}
|
||||
};
|
||||
let mut command = Command::new(&prepared.interpreter);
|
||||
prepared.apply(&mut command);
|
||||
command.arg(script).args(args).current_dir(working_dir);
|
||||
let startup_note = prepared
|
||||
.virtual_env
|
||||
.as_ref()
|
||||
.map(|venv| format!("使用 Python 虚拟环境: {}", venv.display()));
|
||||
self.run_command(task, run_id, cancellation, command, startup_note)
|
||||
.await
|
||||
}
|
||||
TaskAction::Process {
|
||||
executable,
|
||||
@@ -315,7 +330,8 @@ impl TaskExecutor {
|
||||
if let Some(working_dir) = working_dir {
|
||||
command.current_dir(working_dir);
|
||||
}
|
||||
self.run_command(task, run_id, cancellation, command).await
|
||||
self.run_command(task, run_id, cancellation, command, None)
|
||||
.await
|
||||
}
|
||||
TaskAction::Http { .. } => self.run_http(task, run_id, cancellation).await,
|
||||
}
|
||||
@@ -327,6 +343,7 @@ impl TaskExecutor {
|
||||
run_id: i64,
|
||||
cancellation: &CancellationToken,
|
||||
mut command: Command,
|
||||
startup_note: Option<String>,
|
||||
) -> ScriptOutcome {
|
||||
let log_path = self.log_path(&task.id, run_id);
|
||||
let secrets = sensitive_values(&task.action);
|
||||
@@ -342,6 +359,9 @@ impl TaskExecutor {
|
||||
Ok(sink) => sink,
|
||||
Err(error) => return failed_outcome(format!("无法创建运行日志: {error}")),
|
||||
};
|
||||
if let Some(note) = startup_note {
|
||||
sink.system(¬e).await;
|
||||
}
|
||||
|
||||
let job = match ProcessJob::new() {
|
||||
Ok(job) => job,
|
||||
|
||||
Reference in New Issue
Block a user