Skip to content

Commit

Permalink
chore(repo): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Jan 30, 2025
1 parent a0967d3 commit 89b7c21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/nx/src/executors/run-commands/running-tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ class RunningNodeProcess implements RunningTask {

getResults(): Promise<{ code: number; terminalOutput: string }> {
return new Promise((res) => {
this.onExit((code) => {
res({ code, terminalOutput: this.terminalOutput });
this.onExit((code, terminalOutput) => {
res({ code, terminalOutput });
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class NodeChildProcessWithNonDirectOutput implements RunningTask {
}

private async waitForExit(): Promise<number> {
if (!Number.isNaN(this.exitCode)) {
if (typeof this.exitCode === 'number') {
return this.exitCode;
}

Expand Down
21 changes: 13 additions & 8 deletions packages/nx/src/tasks-runner/task-orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class TaskOrchestrator {
private bailed = false;

private runningContinuousTasks = new Map<string, RunningTask>();

private cleaningUp = false;
// endregion internal state

constructor(
Expand Down Expand Up @@ -547,8 +549,8 @@ export class TaskOrchestrator {
try {
const usePtyFork = process.env.NX_NATIVE_COMMAND_RUNNER !== 'false';

// Disable the pseudo terminal if this is a run-many
const disablePseudoTerminal = !this.initiatingProject;
// Disable the pseudo terminal if this is a run-many or when running a continuous task
const disablePseudoTerminal = !this.initiatingProject || task.continuous;
// execution
const childProcess = usePtyFork
? await this.forkedProcessTaskRunner.forkProcess(task, {
Expand Down Expand Up @@ -811,12 +813,14 @@ export class TaskOrchestrator {
);

childProcess.onExit((code) => {
console.error(
`Task "${task.id}" is continuous but exited with code ${code}`
);
this.cleanup().then(() => {
process.exit(1);
});
if (!this.cleaningUp) {
console.error(
`Task "${task.id}" is continuous but exited with code ${code}`
);
this.cleanup().then(() => {
process.exit(1);
});
}
});
if (
this.initiatingProject === task.target.project &&
Expand All @@ -835,6 +839,7 @@ export class TaskOrchestrator {
}

private async cleanup() {
this.cleaningUp = true;
await Promise.all(
Array.from(this.runningContinuousTasks).map(async ([taskId, t]) => {
try {
Expand Down

0 comments on commit 89b7c21

Please sign in to comment.