From c0eecf2128a13637223193edec123efe99fb0b89 Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Wed, 21 Dec 2022 12:15:28 -0600 Subject: [PATCH 1/3] Add failing test --- tests/Fixtures/TestWorkflow.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Fixtures/TestWorkflow.php b/tests/Fixtures/TestWorkflow.php index c94af5a..5f87fcb 100644 --- a/tests/Fixtures/TestWorkflow.php +++ b/tests/Fixtures/TestWorkflow.php @@ -42,10 +42,10 @@ public function execute($shouldAssert = false) assert(! $this->canceled); } - $result = yield ActivityStub::make(TestActivity::class); - yield WorkflowStub::await(fn (): bool => $this->canceled); + $result = yield ActivityStub::make(TestActivity::class); + return 'workflow_' . $result . '_' . $otherResult; } } From 75d6fb11dcec09c1c433896df1e2af8625b94b6f Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Wed, 21 Dec 2022 12:24:47 -0600 Subject: [PATCH 2/3] Resume if already logged --- src/WorkflowStub.php | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/WorkflowStub.php b/src/WorkflowStub.php index 476f468..93050b2 100644 --- a/src/WorkflowStub.php +++ b/src/WorkflowStub.php @@ -109,9 +109,7 @@ public static function await($condition): PromiseInterface 'result' => Y::serialize($result), ]); } catch (QueryException $exception) { - ++self::$context->index; - $deferred = new Deferred(); - return $deferred->promise(); + // already logged } } ++self::$context->index; @@ -142,9 +140,7 @@ public static function awaitWithTimeout($seconds, $condition): PromiseInterface 'result' => Y::serialize($result), ]); } catch (QueryException $exception) { - ++self::$context->index; - $deferred = new Deferred(); - return $deferred->promise(); + // already logged } } ++self::$context->index; @@ -197,9 +193,7 @@ public static function timer($seconds): PromiseInterface 'result' => Y::serialize($result), ]); } catch (QueryException $exception) { - ++self::$context->index; - $deferred = new Deferred(); - return $deferred->promise(); + // already logged } } ++self::$context->index; @@ -290,15 +284,16 @@ public function start(...$arguments): void $this->dispatch(); } - public function fail($throwable): void + public function fail($exception): void { try { $this->storedWorkflow->exceptions() ->create([ 'class' => $this->storedWorkflow->class, - 'exception' => Y::serialize($throwable), + 'exception' => Y::serialize($exception), ]); - } catch (\Throwable) { + } catch (QueryException) { + // already logged } $this->storedWorkflow->status->transitionTo(WorkflowFailedStatus::class); @@ -314,10 +309,8 @@ public function next($index, $now, $class, $result): void 'class' => $class, 'result' => Y::serialize($result), ]); - } catch (QueryException $exception) { - if (! str_contains($exception->getMessage(), 'Duplicate')) { - throw $exception; - } + } catch (QueryException) { + // already logged } $this->dispatch(); From d8ab2a359249199581bf38e033e8b5afae740e6e Mon Sep 17 00:00:00 2001 From: Richard McDaniel Date: Wed, 21 Dec 2022 12:36:14 -0600 Subject: [PATCH 3/3] Update test --- tests/Unit/WorkflowStubTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Unit/WorkflowStubTest.php b/tests/Unit/WorkflowStubTest.php index 8873f01..b9fe254 100644 --- a/tests/Unit/WorkflowStubTest.php +++ b/tests/Unit/WorkflowStubTest.php @@ -62,6 +62,7 @@ public function testComplete(): void $this->assertSame('2022-01-01 00:00:00', WorkflowStub::now()->toDateTimeString()); $this->assertSame(WorkflowCompletedStatus::class, $workflow->status()); $this->assertSame('workflow', $workflow->output()); + $this->assertSame(1, $workflow->exceptions()->count()); $this->assertSame(1, $workflow->logs()->count()); } @@ -115,7 +116,7 @@ public function testAwaitWithTimeout(): void $this->assertSame(0, WorkflowStub::getContext()->index); - $promise = WorkflowStub::awaitWithTimeout('1 minute', static fn () => false); + $promise = WorkflowStub::awaitWithTimeout(60, static fn () => false); $this->assertSame(1, $workflow->logs()->count()); $this->assertSame(1, WorkflowStub::getContext()->index); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy