Skip to content

Commit

Permalink
refactor: clarify when to process next batch
Browse files Browse the repository at this point in the history
The held state doesn't constitute an error but should stop the next
batch from processing. The next batch logic should only continue if all
futures are completed successfully. That is now reflected in the view
function.
  • Loading branch information
kanej committed Sep 12, 2023
1 parent 5891fe5 commit 0748561
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
6 changes: 4 additions & 2 deletions packages/core/src/internal/execution/execution-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { DeploymentLoader } from "../deployment-loader/types";
import { getFuturesFromModule } from "../utils/get-futures-from-module";
import { getPendingNonceAndSender } from "../views/execution-state/get-pending-nonce-and-sender";
import { hasExecutionFailed } from "../views/has-execution-failed";
import { hasExecutionSucceeded } from "../views/has-execution-succeeded";

import { applyNewMessage } from "./deployment-state-helpers";
import { FutureProcessor } from "./future-processor/future-processor";
Expand Down Expand Up @@ -107,7 +107,9 @@ export class ExecutionEngine {
deploymentState
);

if (executionBatch.some((f) => hasExecutionFailed(f, deploymentState))) {
if (
!executionBatch.every((f) => hasExecutionSucceeded(f, deploymentState))
) {
return deploymentState;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ import { DeploymentState } from "../execution/types/deployment-state";
import { ExecutionStatus } from "../execution/types/execution-state";

/**
* Returns true if the execution of the given future has failed.
* Returns true if the execution of the given future has succeeded.
*
* @param future The future.
* @param deploymentState The deployment state to check against.
* @returns true if it failed.
* @returns true if it succeeded.
*/
export function hasExecutionFailed(
export function hasExecutionSucceeded(
future: Future,
deploymentState: DeploymentState
): boolean {
const exState = deploymentState.executionStates[future.id];

if (exState === undefined) {
return false;
}

return (
exState.status === ExecutionStatus.FAILED ||
exState.status === ExecutionStatus.TIMEOUT ||
exState.status === ExecutionStatus.HELD
);
return exState.status === ExecutionStatus.SUCCESS;
}

0 comments on commit 0748561

Please sign in to comment.