Skip to content

Commit

Permalink
Merge pull request #45 from SDPM-lab/dev
Browse files Browse the repository at this point in the history
v0.1.4-beta Release.
  • Loading branch information
ping-yee authored Mar 5, 2023
2 parents fd61cb4 + d4fca45 commit c667d69
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function definition(int $product_key = null, int $product_amount = nul

$cache = CacheFactory::initCacheDriver('redis', 'tcp://anser_redis:6379');

$this->setServerName("server_3");
$this->setServerName("Anser_Server_1");

// Step 1. Check the product inventory balance.
$step1 = $this->setStep()->addAction(
Expand Down
6 changes: 3 additions & 3 deletions develop/app/Controllers/v2/CreateOrderRestarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function restartCreateOrderOrchestratorByServerName()

$userOrchRestarter = new Restarter();

$result = $userOrchRestarter->reStartOrchestratorsByServer(CreateOrderOrchestrator::class, 'server_1');
$result = $userOrchRestarter->reStartOrchestratorsByServer(CreateOrderOrchestrator::class, 'Anser_Server_1');

return $this->respond([
"result" => $result
Expand All @@ -33,7 +33,7 @@ public function restartCreateOrderOrchestratorByServerCluster()

$result = $userOrchRestarter->reStartOrchestratorsByServer(
CreateOrderOrchestrator::class,
["server_1", "server_2"]
["Anser_Server_1", "Anser_Server_2"]
);

return $this->respond([
Expand All @@ -60,7 +60,7 @@ public function restartCreateOrderOrchestratorByServerNameAndNeedRestart()

$userOrchRestarter = new Restarter();

$result = $userOrchRestarter->reStartOrchestratorsByServer(CreateOrderOrchestrator::class, 'server_1', true);
$result = $userOrchRestarter->reStartOrchestratorsByServer(CreateOrderOrchestrator::class, 'Anser_Server_1', true);

return $this->respond([
"result" => $result
Expand Down
5 changes: 5 additions & 0 deletions src/Exception/OrchestratorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public static function forSagaInstanceNotFoundInCache(): OrchestratorException
{
return new self("在重啟邏輯需先設定 Saga 補償邏輯。");
}

public static function forStepActionMeaningDataIsNull($alias): OrchestratorException
{
return new self("此步驟- {$alias} 的 Action 的 meaningData 為 null,請確認 setMeaningData 方法或是此步驟尚未被處理。");
}
}
3 changes: 3 additions & 0 deletions src/Orchestration/Orchestrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ public function getStepAction(string $alias): ActionInterface
{
foreach ($this->steps as $step) {
if (!$step->aliasNonRepeat($alias)) {
if ($step->getStepAction($alias)->getMeaningData() === null) {
throw OrchestratorException::forStepActionMeaningDataIsNull($alias);
}
return $step->getStepAction($alias);
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/Orchestration/Saga/Restarter/Restarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,25 @@ public function reStartOrchestratorsByServer(
foreach ($serverName as $key => $singleServerName) {
$runtimeOrchArray = $this->cacheInstance->getOrchestratorsByServerName($singleServerName, $className);

$this->handleSingleServerRestart($singleServerName, $runtimeOrchArray, $isRestart);
if ($runtimeOrchArray === null) {
$this->serverRestartResult[$serverName] = [
"compensateResult" => "編排器名稱 - {$className} 不存在於 {$serverName} 內。"
];
continue;
} else {
$this->handleSingleServerRestart($singleServerName, $runtimeOrchArray, $isRestart);
}
}
} elseif (is_string($serverName)) {
$runtimeOrchArray = $this->cacheInstance->getOrchestratorsByServerName($serverName, $className);

$this->handleSingleServerRestart($serverName, $runtimeOrchArray, $isRestart);
if ($runtimeOrchArray === null) {
$this->serverRestartResult[$serverName] = [
"compensateResult" => "編排器名稱 - {$className} 不存在於 {$serverName} 內。"
];
} else {
$this->handleSingleServerRestart($serverName, $runtimeOrchArray, $isRestart);
}
}

return $this->serverRestartResult;
Expand Down
8 changes: 7 additions & 1 deletion src/Orchestration/Step.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Step implements StepInterface
/**
* 儲存 Step 中的 array,其資料結構為 陣列<別名,Action實體>
*
* @var array<string,ActionInterface>
* @var array<string,ActionInterface|callable>
*/
protected array $actionList = [];

Expand Down Expand Up @@ -197,6 +197,12 @@ protected function handleActionCallable(
*/
public function getStepAction(string $alias): ActionInterface
{
// If the step is not run yet and it's action type callable,
// call the function to handle it.
if (is_callable($this->actionList[$alias]) === true) {
$this->handleActionCallable($alias, $this->actionList[$alias]);
}

if (!isset($this->actionList[$alias])) {
throw StepException::forUndefinedStepAction($alias);
}
Expand Down

0 comments on commit c667d69

Please sign in to comment.