Skip to content

Commit

Permalink
2023.10.1 Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
monkenWu committed Oct 1, 2023
2 parents 9a9781c + 974d5ea commit cf6afbd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
22 changes: 20 additions & 2 deletions src/Orchestration/Orchestrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,25 @@ final public function build(...$args)
return $result;
}

public function reBuild()
{
$this->steps = [];
$this->isSuccess = true;
$this->isCompensationSuccess = true;
$this->sagaInstance = null;
call_user_func_array(array($this, "definition"), $this->argsArray);

$this->startAllStep();

if($this->isSuccess()){
$result = $this->defineResult();
} else{
$result = $this->defineFailResult();
}

return $result;
}

/**
* Handle the single step of steps array.
*
Expand Down Expand Up @@ -268,7 +287,7 @@ protected function handleSingleStep(StepInterface $step)
*
* @return void
*/
public function startAllStep(CacheHandlerInterface $cacheInstance = null)
public function startAllStep()
{
$cacheInstance = null;
if($this->useBackup){
Expand All @@ -283,7 +302,6 @@ public function startAllStep(CacheHandlerInterface $cacheInstance = null)
foreach ($this->steps as $step) {
$this->handleSingleStep($step);
//若有執行交易,中止 Step 的執行,並開始補償

if ($this->isSuccess() === false) {
if (is_null($this->sagaInstance) === false) {
$transResult = $this->startOrchCompensation();
Expand Down
25 changes: 18 additions & 7 deletions src/Orchestration/Saga/Restarter/Restarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public function reStartOrchestratorsByServer(
$this->handleSingleServerRestart($serverName, $runtimeOrchArray, $isRestart);
}
}

return $this->serverRestartResult;
}

Expand Down Expand Up @@ -154,15 +153,26 @@ protected function handleSingleServerRestart(string $serverName, array $runtimeO
$serverName
);

$compensateUserResult = [];
//only need orchestratorNumber and compensateResult
foreach ($compensateResult as $orchestratorNumber => $data) {
$compensateUserResult[$orchestratorNumber] = $data["compensateResult"];
}
// Store the compensate result.
$this->serverRestartResult[$serverName] = [
"compensateResult" => $compensateResult
"compensateResult" => $compensateUserResult
];

// If the $isRestart is true, it will handle the restart all step of the runtime Orch and store the result.
if ($isRestart === true) {
$rebuiltResult = $this->handleRuntimeOrchArrayRestart($compensateResult);
$rebuiltUserResult = [];
//only need orchestratorNumber and restartResult
foreach ($rebuiltResult as $orchestratorNumber => $data) {
$rebuiltUserResult[$orchestratorNumber] = $data["restartResult"];
}
$this->serverRestartResult[$serverName] = [
"restartResult" => $this->handleRuntimeOrchArrayRestart($compensateResult)
"restartResult" => $rebuiltUserResult
];
}
}
Expand All @@ -185,7 +195,8 @@ protected function handleRuntimeOrchArrayCompensate(array $runtimeOrchArray, str

// Compensate
$compensateResult[$runtimeOrch->getOrchestratorNumber()] = [
"compensateResult" => $runtimeOrch->startOrchCompensation()
"compensateResult" => $runtimeOrch->startOrchCompensation(),
"runtimeOrchestrator" => $runtimeOrch
];

if ($compensateResult[$runtimeOrch->getOrchestratorNumber()] === false) {
Expand All @@ -209,14 +220,14 @@ protected function handleRuntimeOrchArrayRestart(array $compensateResultArray):
{
$restartResult = [];

foreach ($compensateResultArray as $orchestratorNumber => $compensateResult) {
foreach ($compensateResultArray as &$compensateResult) {
if ($compensateResult["compensateResult"] === false) {
continue;
}

/** @var OrchestratorInterface */
$runtimeOrch = $compensateResult["runtimeOrchestrator"];

$runtimeOrch->startAllStep();
$runtimeOrch->reBuild();

$restartResult[$runtimeOrch->getOrchestratorNumber()] = [
"restartResult" => $runtimeOrch->isSuccess()
Expand Down

0 comments on commit cf6afbd

Please sign in to comment.