Skip to content

Commit ef9ee5a

Browse files
committed
Only start an attempt if not finished. Send message to worker if pending executing
1 parent a968c23 commit ef9ee5a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

internal-packages/run-engine/src/engine/systems/runAttemptSystem.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ import { runStatusFromError, ServiceValidationError } from "../errors.js";
4141
import { sendNotificationToWorker } from "../eventBus.js";
4242
import { getMachinePreset, machinePresetFromName } from "../machinePresets.js";
4343
import { retryOutcomeFromCompletion } from "../retrying.js";
44-
import { isExecuting, isInitialState } from "../statuses.js";
44+
import {
45+
isExecuting,
46+
isFinishedOrPendingFinished,
47+
isInitialState,
48+
isPendingExecuting,
49+
} from "../statuses.js";
4550
import { RunEngineOptions } from "../types.js";
4651
import { BatchSystem } from "./batchSystem.js";
4752
import { DelayedRunSystem } from "./delayedRunSystem.js";
@@ -345,8 +350,8 @@ export class RunAttemptSystem {
345350
span.setAttribute("taskRunId", taskRun.id);
346351
span.setAttribute("taskRunFriendlyId", taskRun.friendlyId);
347352

348-
if (taskRun.status === "CANCELED") {
349-
throw new ServiceValidationError("Task run is cancelled", 400);
353+
if (isFinishedOrPendingFinished(latestSnapshot.executionStatus)) {
354+
throw new ServiceValidationError("Task run is already finished", 400);
350355
}
351356

352357
if (!taskRun.lockedById) {
@@ -1321,7 +1326,10 @@ export class RunAttemptSystem {
13211326
});
13221327

13231328
//if executing, we need to message the worker to cancel the run and put it into `PENDING_CANCEL` status
1324-
if (isExecuting(latestSnapshot.executionStatus)) {
1329+
if (
1330+
isExecuting(latestSnapshot.executionStatus) ||
1331+
isPendingExecuting(latestSnapshot.executionStatus)
1332+
) {
13251333
const newSnapshot = await this.executionSnapshotSystem.createExecutionSnapshot(prisma, {
13261334
run,
13271335
snapshot: {

0 commit comments

Comments
 (0)