Skip to content

Commit 0f78165

Browse files
committed
Rename struct.
1 parent 50bd756 commit 0f78165

5 files changed

Lines changed: 35 additions & 30 deletions

File tree

crates/task-runner/src/command_builder.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing::{debug, instrument, trace};
1818

1919
pub struct CommandBuilder<'task> {
2020
app: &'task AppContext,
21-
node: &'task ActionNode,
21+
node: Option<&'task ActionNode>,
2222
project: &'task Project,
2323
task: &'task Task,
2424
working_dir: &'task Path,
@@ -29,12 +29,7 @@ pub struct CommandBuilder<'task> {
2929
}
3030

3131
impl<'task> CommandBuilder<'task> {
32-
pub fn new(
33-
app: &'task AppContext,
34-
project: &'task Project,
35-
task: &'task Task,
36-
node: &'task ActionNode,
37-
) -> Self {
32+
pub fn new(app: &'task AppContext, project: &'task Project, task: &'task Task) -> Self {
3833
let working_dir = if task.options.run_from_workspace_root {
3934
&app.workspace_root
4035
} else {
@@ -43,7 +38,7 @@ impl<'task> CommandBuilder<'task> {
4338

4439
Self {
4540
app,
46-
node,
41+
node: None,
4742
project,
4843
task,
4944
working_dir,
@@ -57,7 +52,14 @@ impl<'task> CommandBuilder<'task> {
5752
}
5853

5954
#[instrument(name = "build_command", skip_all)]
60-
pub async fn build(mut self, context: &ActionContext, hash: &str) -> miette::Result<Command> {
55+
pub async fn build(
56+
mut self,
57+
context: &ActionContext,
58+
node: &'task ActionNode,
59+
hash: &str,
60+
) -> miette::Result<Command> {
61+
self.node = Some(node);
62+
6163
debug!(
6264
task_target = self.task.target.as_str(),
6365
working_dir = ?self.working_dir,
@@ -116,7 +118,7 @@ impl<'task> CommandBuilder<'task> {
116118
#[instrument(skip_all)]
117119
fn inject_args(&mut self, context: &ActionContext) {
118120
// Must be first!
119-
if let ActionNode::RunTask(inner) = &self.node
121+
if let Some(ActionNode::RunTask(inner)) = &self.node
120122
&& !inner.args.is_empty()
121123
{
122124
trace!(
@@ -148,7 +150,7 @@ impl<'task> CommandBuilder<'task> {
148150
let mut moon_env = FxHashMap::<String, Option<String>>::default();
149151

150152
// Inherit task dependent variables
151-
if let ActionNode::RunTask(inner) = &self.node
153+
if let Some(ActionNode::RunTask(inner)) = &self.node
152154
&& !inner.env.is_empty()
153155
{
154156
trace!(

crates/task-runner/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Public for tests
2+
mod checks_runner;
23
pub mod command_builder;
3-
pub mod command_executor;
44
pub mod manifest_compat;
55
pub mod output_archiver;
66
pub mod output_hydrater;
77
mod run_state;
8+
pub mod task_executor;
89
mod task_runner;
910
mod task_runner_error;
1011

crates/task-runner/src/command_executor.rs renamed to crates/task-runner/src/task_executor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ use tokio_util::sync::CancellationToken;
1414
use tracing::{debug, instrument};
1515

1616
#[derive(Debug)]
17-
pub struct CommandExecuteResult {
17+
pub struct TaskExecuteResult {
1818
pub attempts: OperationList,
1919
pub error: Option<miette::Report>,
2020
pub run_state: TargetState,
2121
}
2222

2323
/// Run the command as a child process and capture its output. If the process fails
2424
/// and `retry_count` is greater than 0, attempt the process again in case it passes.
25-
pub struct CommandExecutor<'task> {
25+
pub struct TaskExecutor<'task> {
2626
app: &'task AppContext,
2727
task: &'task Task,
2828
project: &'task Project,
@@ -40,7 +40,7 @@ pub struct CommandExecutor<'task> {
4040
stream: bool,
4141
}
4242

43-
impl<'task> CommandExecutor<'task> {
43+
impl<'task> TaskExecutor<'task> {
4444
pub fn new(
4545
app: &'task AppContext,
4646
project: &'task Project,
@@ -70,7 +70,7 @@ impl<'task> CommandExecutor<'task> {
7070
mut self,
7171
context: &ActionContext,
7272
report_item: &mut TaskReportItem,
73-
) -> miette::Result<CommandExecuteResult> {
73+
) -> miette::Result<TaskExecuteResult> {
7474
// Prepare state for the executor, and each attempt
7575
let mut run_state = TargetState::Failed;
7676

@@ -237,7 +237,7 @@ impl<'task> CommandExecutor<'task> {
237237

238238
self.stop_monitoring();
239239

240-
Ok(CommandExecuteResult {
240+
Ok(TaskExecuteResult {
241241
attempts: self.attempts.take(),
242242
error: execution_error,
243243
run_state,
@@ -342,7 +342,7 @@ impl<'task> CommandExecutor<'task> {
342342
}
343343
}
344344

345-
impl Drop for CommandExecutor<'_> {
345+
impl Drop for TaskExecutor<'_> {
346346
fn drop(&mut self) {
347347
self.stop_monitoring();
348348
}

crates/task-runner/src/task_runner.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::command_builder::CommandBuilder;
2-
use crate::command_executor::CommandExecutor;
32
use crate::output_archiver::{ArchiveOutcome, OutputArchiver};
43
use crate::output_hydrater::{HydrateFrom, HydrateOutcome, OutputHydrater};
54
use crate::run_state::*;
5+
use crate::task_executor::TaskExecutor;
66
use crate::task_runner_error::TaskRunnerError;
77
use moon_action::{ActionNode, ActionStatus, Operation, OperationList, OperationMeta};
88
use moon_action_context::{ActionContext, TargetState};
@@ -432,13 +432,16 @@ impl<'task> TaskRunner<'task> {
432432
);
433433

434434
// Build the command from the current task
435-
let command = CommandBuilder::new(self.app_context, self.project, self.task, node)
436-
.build(context, self.report.hash.as_deref().unwrap_or_default())
435+
let command = CommandBuilder::new(self.app_context, self.project, self.task)
436+
.build(
437+
context,
438+
node,
439+
self.report.hash.as_deref().unwrap_or_default(),
440+
)
437441
.await?;
438442

439443
// Execute the command and gather all attempts made
440-
let executor =
441-
CommandExecutor::new(self.app_context, self.project, self.task, node, command);
444+
let executor = TaskExecutor::new(self.app_context, self.project, self.task, node, command);
442445

443446
let result = if let Some(mutex_name) = &self.task.options.mutex {
444447
let mut operation = Operation::mutex_acquisition();

crates/task-runner/tests/utils.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use moon_task::Task;
1313
use moon_task_runner::TaskRunState;
1414
use moon_task_runner::TaskRunner;
1515
use moon_task_runner::command_builder::CommandBuilder;
16-
use moon_task_runner::command_executor::CommandExecutor;
1716
use moon_task_runner::output_archiver::OutputArchiver;
1817
use moon_task_runner::output_hydrater::OutputHydrater;
18+
use moon_task_runner::task_executor::TaskExecutor;
1919
use moon_test_utils::{WorkspaceGraph, WorkspaceMocker};
2020
use starbase_archive::Archiver;
2121
use starbase_sandbox::{Sandbox, create_sandbox};
@@ -179,10 +179,10 @@ impl TaskRunnerContainer {
179179
self.internal_create_command(&context, &task, &node).await
180180
}
181181

182-
pub async fn create_command_executor(&self, context: &ActionContext) -> CommandExecutor<'_> {
182+
pub async fn create_command_executor(&self, context: &ActionContext) -> TaskExecutor<'_> {
183183
let node = create_node(&self.task);
184184

185-
CommandExecutor::new(
185+
TaskExecutor::new(
186186
&self.app_context,
187187
&self.project,
188188
&self.task,
@@ -236,9 +236,8 @@ impl TaskRunnerContainer {
236236

237237
pub async fn create_check_command(&self, check: &moon_task::TaskCheckEntry) -> Command {
238238
let task = self.task.as_ref();
239-
let node = create_node(task);
240239

241-
let mut builder = CommandBuilder::new(&self.app_context, &self.project, task, &node);
240+
let mut builder = CommandBuilder::new(&self.app_context, &self.project, task);
242241
builder.set_env_bag(&self.env_bag);
243242
builder.build_check(check).await.unwrap()
244243
}
@@ -249,8 +248,8 @@ impl TaskRunnerContainer {
249248
task: &Task,
250249
node: &ActionNode,
251250
) -> Command {
252-
let mut builder = CommandBuilder::new(&self.app_context, &self.project, task, node);
251+
let mut builder = CommandBuilder::new(&self.app_context, &self.project, task);
253252
builder.set_env_bag(&self.env_bag);
254-
builder.build(context, "abc123").await.unwrap()
253+
builder.build(context, node, "abc123").await.unwrap()
255254
}
256255
}

0 commit comments

Comments
 (0)