From fc78a23cef7beaddeacafc0a5698bbdc93f03346 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 2 Jul 2024 23:13:18 +0400 Subject: [PATCH 1/3] Add a test case with ContinueAsNew on non-default task queue --- .../ContinuaWithTaskQueueWorkflow.php | 46 +++++++++++++++++++ tests/Functional/NamedArgumentsTestCase.php | 21 +++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/Fixtures/src/Workflow/ContinuaWithTaskQueueWorkflow.php diff --git a/tests/Fixtures/src/Workflow/ContinuaWithTaskQueueWorkflow.php b/tests/Fixtures/src/Workflow/ContinuaWithTaskQueueWorkflow.php new file mode 100644 index 000000000..eb3beeec1 --- /dev/null +++ b/tests/Fixtures/src/Workflow/ContinuaWithTaskQueueWorkflow.php @@ -0,0 +1,46 @@ +withStartToCloseTimeout(5) + ); + + if ($generation > 5) { + // complete + return Workflow::getInfo()->taskQueue . $generation; + } + + if ($generation !== 1) { + assert(!empty(Workflow::getInfo()->continuedExecutionRunId)); + } + + for ($i = 0; $i < $generation; $i++) { + yield $simple->echo((string)$generation); + } + + return Workflow::newContinueAsNewStub(self::class)->handler(++$generation); + } +} diff --git a/tests/Functional/NamedArgumentsTestCase.php b/tests/Functional/NamedArgumentsTestCase.php index bcce1babf..58ca91933 100644 --- a/tests/Functional/NamedArgumentsTestCase.php +++ b/tests/Functional/NamedArgumentsTestCase.php @@ -6,6 +6,9 @@ use Temporal\Client\GRPC\ServiceClient; use Temporal\Client\WorkflowClient; +use Temporal\Client\WorkflowOptions; +use Temporal\Tests\Workflow\ContinuableWorkflow; +use Temporal\Tests\Workflow\ContinuaWithTaskQueueWorkflow; use Temporal\Tests\Workflow\NamedArguments\ContinueAsNewNamedArgumentsWorkflow; use Temporal\Tests\Workflow\NamedArguments\ExecuteChildNamedArgumentsWorkflow; use Temporal\Tests\Workflow\NamedArguments\ActivityNamedArgumentsWorkflow; @@ -213,6 +216,24 @@ public function testContinueAsNewNamedArguments() ], $result); } + /** + * TaskQueue must be inherited from the parent workflow + */ + public function testContinueAsNewTaskQueue(): void + { + $workflow = $this->workflowClient->newWorkflowStub( + ContinuaWithTaskQueueWorkflow::class, + WorkflowOptions::new()->withTaskQueue('FooBar'), + ); + + $result = $this->workflowClient->start( + $workflow, + generation: 1, + )->getResult(); + + self::assertSame('FooBar6', $result); + } + public function testExecuteChildNamedArguments() { $this->markTestSkipped( From 77328e3da76a3cfda2259e726ce403966e02807b Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 2 Jul 2024 23:14:12 +0400 Subject: [PATCH 2/3] Try to inherit TaskQueue from the parent when ContinueAsNew options DTO is created --- src/Workflow/ContinueAsNewOptions.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Workflow/ContinueAsNewOptions.php b/src/Workflow/ContinueAsNewOptions.php index 2bda8709e..08af4bfb4 100644 --- a/src/Workflow/ContinueAsNewOptions.php +++ b/src/Workflow/ContinueAsNewOptions.php @@ -18,6 +18,7 @@ use Temporal\Internal\Support\DateInterval; use Temporal\Worker\WorkerFactoryInterface; use Temporal\Worker\Worker; +use Temporal\Workflow; /** * @psalm-import-type DateIntervalValue from DateInterval @@ -55,6 +56,12 @@ public function __construct() { $this->workflowRunTimeout = CarbonInterval::seconds(0); $this->workflowTaskTimeout = CarbonInterval::seconds(0); + try { + // Inherit TaskQueue from the current Workflow if possible + $this->taskQueue = Workflow::getInfo()->taskQueue; + } catch (\Throwable) { + // Do nothing + } } /** From c470f2cf4dabf4802ad307ea6e886ebb1c2b15f0 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 2 Jul 2024 23:17:19 +0400 Subject: [PATCH 3/3] Fix psalm issue --- psalm-baseline.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index e6ccb4cd8..aa1b9cbf8 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1202,7 +1202,7 @@ $request = new SignalExternalWorkflow( $this->getOptions()->namespace, $execution->getID(), - $execution->getRunID(), + null, $name, EncodedValues::fromValues($args), true,