Skip to content

Commit 7217da0

Browse files
committed
feat(task): support fast failure exit
1 parent e81cb21 commit 7217da0

5 files changed

Lines changed: 107 additions & 1 deletion

File tree

crates/vite_task/src/schedule.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub struct PreExecutionStatus {
3232
pub cache_status: CacheStatus,
3333
pub display_options: DisplayOptions,
3434
}
35+
3536
#[derive(Debug, Serialize, Deserialize, Clone)]
3637
pub enum CacheStatus {
3738
/// Cache miss with reason.
@@ -127,8 +128,31 @@ impl ExecutionPlan {
127128
#[tracing::instrument(skip(self, workspace))]
128129
pub async fn execute(self, workspace: &mut Workspace) -> Result<ExecutionSummary, Error> {
129130
let mut execution_statuses = Vec::<ExecutionStatus>::with_capacity(self.steps.len());
131+
let mut has_failed = false;
130132
for step in self.steps {
131-
execution_statuses.push(Self::execute_resolved_task(step, workspace).await?);
133+
if has_failed {
134+
// skip executing the task and display the task name and index
135+
let display_options = step.display_options;
136+
execution_statuses.push(ExecutionStatus {
137+
execution_id: Uuid::new_v4().to_string(),
138+
pre_execution_status: PreExecutionStatus {
139+
display_command: get_display_command(display_options, &step),
140+
task: step,
141+
cache_status: CacheStatus::CacheMiss(CacheMiss::NotFound),
142+
display_options,
143+
},
144+
execution_result: Err(ExecutionFailure::SkippedDueToFailedDependency),
145+
});
146+
continue;
147+
}
148+
149+
let status = Self::execute_resolved_task(step, workspace).await?;
150+
if let Ok(exit_status) = status.execution_result {
151+
if exit_status != 0 {
152+
has_failed = true;
153+
}
154+
}
155+
execution_statuses.push(status);
132156
}
133157
Ok(ExecutionSummary { execution_statuses })
134158
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log('failure');
2+
process.exit(1);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"scripts": {
3+
"ready": "vite run test && vite run script4",
4+
"test": "vite run script1 && vite run script2 && vite run script3",
5+
"script1": "echo 'success 1'",
6+
"script2": "node failure.js",
7+
"script3": "echo 'success 3'",
8+
"script4": "echo 'success 4'"
9+
}
10+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[1]> vite run test # skip script3 when script2 failed
2+
$ echo 'success 1'
3+
success 1
4+
5+
6+
$ node failure.js
7+
failure
8+
9+
10+
11+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
12+
Vite+ Task Runner • Execution Summary
13+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
14+
15+
Statistics: 3 tasks • 0 cache hits • 3 cache misses • 1 failed
16+
Performance: 0% cache hit rate
17+
18+
Task Details:
19+
────────────────────────────────────────────────
20+
[1] script1: $ echo 'success 1' ✓
21+
→ Cache miss: no previous cache entry found
22+
·······················································
23+
[2] script2: $ node failure.js ✗ (exit code: 1)
24+
→ Cache miss: no previous cache entry found
25+
·······················································
26+
[3] test: $ vite run script3 ⊘ (skipped: dependency failed)
27+
→ Cache miss: no previous cache entry found
28+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
29+
30+
[1]> vite run ready # support nested tasks
31+
$ echo 'success 1' (✓ cache hit, replaying)
32+
success 1
33+
34+
35+
$ node failure.js
36+
failure
37+
38+
39+
40+
41+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
42+
Vite+ Task Runner • Execution Summary
43+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
44+
45+
Statistics: 4 tasks • 1 cache hits • 3 cache misses • 1 failed
46+
Performance: 25% cache hit rate, <variable>ms saved in total
47+
48+
Task Details:
49+
────────────────────────────────────────────────
50+
[1] script1: $ echo 'success 1' ✓
51+
→ Cache hit - output replayed - <variable>ms saved
52+
·······················································
53+
[2] script2: $ node failure.js ✗ (exit code: 1)
54+
→ Cache miss: no previous cache entry found
55+
·······················································
56+
[3] test: $ vite run script3 ⊘ (skipped: dependency failed)
57+
→ Cache miss: no previous cache entry found
58+
·······················································
59+
[4] ready: $ vite run script4 ⊘ (skipped: dependency failed)
60+
→ Cache miss: no previous cache entry found
61+
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"env": {
3+
"VITE_DISABLE_AUTO_INSTALL": "1"
4+
},
5+
"commands": [
6+
"vite run test # skip script3 when script2 failed",
7+
"vite run ready # support nested tasks"
8+
]
9+
}

0 commit comments

Comments
 (0)