Skip to content

Commit

Permalink
Merge pull request #51 from SDPM-lab/dev
Browse files Browse the repository at this point in the history
Support PHP 7.4
  • Loading branch information
monkenWu authored Sep 15, 2023
2 parents 461d2a7 + 9b06357 commit 9983bc6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
5 changes: 5 additions & 0 deletions src/Exception/OrchestratorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ public static function forStepActionMeaningDataIsNull($alias): OrchestratorExcep
{
return new self("此步驟- {$alias} 的 Action 的 meaningData 為 null,請確認 setMeaningData 方法或是此步驟尚未被處理。");
}

public static function forStepExecuteFail($className, $motion): OrchestratorException
{
return new self("The orchestrator - {$className} {$motion} Fail at " . date("Y-m-d H:i:s"));
}
}
24 changes: 4 additions & 20 deletions src/Orchestration/Orchestrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function startAllStep(CacheHandlerInterface $cacheInstance = null)
{
$cacheInstance = $cacheInstance ?? CacheFactory::getCacheInstance();

$this->orchestratorNumber = $this::class . '\\' . md5(json_encode($this->argsArray) . uniqid("", true)) . '\\' . date("Y-m-d H:i:s");
$this->orchestratorNumber = static::class . '\\' . md5(json_encode($this->argsArray) . uniqid("", true)) . '\\' . date("Y-m-d H:i:s");

// Set up the cache info/variable if developer set the cache instance.
if (!is_null($cacheInstance)) {
Expand All @@ -281,33 +281,17 @@ public function startAllStep(CacheHandlerInterface $cacheInstance = null)

if ($this->isSuccess() === false) {
if (is_null($this->sagaInstance) === false) {
if ($this->startOrchCompensation()) {
log_message(
"notice",
"The orchestrator" . $this::class . "compensate completely at " . date("Y-m-d H:i:s")
);
} else {
log_message(
"critical",
"The orchestrator" . $this::class . "compensate Fail at " . date("Y-m-d H:i:s")
);
if (!$this->startOrchCompensation() || is_null($this->startOrchCompensation())) {
throw OrchestratorException::forStepExecuteFail(static::class, "compensate");
}
} else {
log_message(
"critical",
"The orchestrator" . $this::class . "run Fail at " . date("Y-m-d H:i:s")
);
throw OrchestratorException::forStepExecuteFail(static::class, "run");
}

break;
}
}

log_message(
"notice",
"The orchestrator" . $this::class . "orchestrator completely at " . date("Y-m-d H:i:s")
);

// 當所有 Step 執行完成且都執行成功,則清除在快取的編排器
// 並儲存 Log 進資料庫
if (!is_null($cacheInstance)) {
Expand Down
6 changes: 5 additions & 1 deletion src/Orchestration/Saga/Saga.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ public function getState(): StateInterface
*/
protected function canStartCompensation(): bool
{
$nowStep = $this->stateInstance->getNowStep()?->getNumber();
$nowStep = null;

if (!is_null($this->stateInstance->getNowStep())) {
$nowStep = $this->stateInstance->getNowStep()->getNumber();
}

if (is_null($nowStep)) {
return false;
Expand Down

0 comments on commit 9983bc6

Please sign in to comment.