Skip to content

Commit

Permalink
Merge pull request #452: Fix Child Workflow Task Queue Inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Jun 11, 2024
2 parents a73b1fb + f35f0c4 commit cc87986
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/Workflow/ChildWorkflowOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ public function __construct()
$this->workflowRunTimeout = CarbonInterval::seconds(0);
$this->workflowTaskTimeout = CarbonInterval::seconds(0);

// Inherit Namespace and TaskQueue from the current Workflow if possible
try {
// Inherit namespace from the current Workflow if possible
$this->namespace = Workflow::getInfo()->namespace;
$info = Workflow::getInfo();
$this->namespace = $info->namespace;
$this->taskQueue = $info->taskQueue;
} catch (\Throwable) {
// Do nothing
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Fixtures/data/Test_ExecuteChildWorkflowTaskQueue.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
2021/01/12 15:29:11 DEBUG [{"command":"StartWorkflow","options":{"info":{"WorkflowExecution":{"ID":"ab0dac3f-df7e-44ea-9964-c67aadfffcbf","RunID":"eede8d74-cabb-4c49-bd0d-b87f14306d33"},"WorkflowType":{"Name":"WithChildWorkflow"},"TaskQueueName":"FooBar","WorkflowExecutionTimeout":315360000000000000,"WorkflowRunTimeout":315360000000000000,"WorkflowTaskTimeout":0,"Namespace":"foobar","Attempt":1,"CronSchedule":"","ContinuedExecutionRunID":"","ParentWorkflowNamespace":"","ParentWorkflowExecution":null,"Memo":null,"SearchAttributes":null,"BinaryChecksum":"0843e92328c0fb62c02212ed103edb4d"}},"payloads":"CicKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SDSJIZWxsbyBXb3JsZCI="}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.7617832Z"}
2021/01/12 15:29:11 DEBUG [{"id":9001,"command":"ExecuteChildWorkflow","options":{"name":"SimpleWorkflow","options":{"Namespace":"foobar","WorkflowID":null,"TaskQueueName":"FooBar","WorkflowExecutionTimeout":0,"WorkflowRunTimeout":0,"WorkflowTaskTimeout":0,"WaitForCancellation":false,"WorkflowIDReusePolicy":2,"RetryPolicy":null,"CronSchedule":null,"ParentClosePolicy":1,"Memo":null,"SearchAttributes":null}},"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJjaGlsZCBIZWxsbyBXb3JsZCI=","header":""},{"id":9002,"command":"GetChildWorkflowExecution","options":{"id":9001},"payloads":"","header":""},{"payloads":"ChkKFwoIZW5jb2RpbmcSC2JpbmFyeS9udWxs"}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9002,"payloads":"CngKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SXnsiSUQiOiJlZWRlOGQ3NC1jYWJiLTRjNDktYmQwZC1iODdmMTQzMDZkMzNfMSIsIlJ1bklEIjoiNDMyMDgxZGItZGQyZS00ODY1LTk0MDctZTNjM2Y5NWYyZTc0In0="}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.8333619Z"}
2021/01/12 15:29:11 DEBUG [{"command":"StartWorkflow","options":{"info":{"WorkflowExecution":{"ID":"eede8d74-cabb-4c49-bd0d-b87f14306d33_1","RunID":"432081db-dd2e-4865-9407-e3c3f95f2e74"},"WorkflowType":{"Name":"SimpleWorkflow"},"TaskQueueName":"FooBar","WorkflowExecutionTimeout":0,"WorkflowRunTimeout":0,"WorkflowTaskTimeout":0,"Namespace":"foobar","Attempt":1,"CronSchedule":"","ContinuedExecutionRunID":"","ParentWorkflowNamespace":"default","ParentWorkflowExecution":{"ID":"ab0dac3f-df7e-44ea-9964-c67aadfffcbf","RunID":"eede8d74-cabb-4c49-bd0d-b87f14306d33"},"Memo":null,"SearchAttributes":null,"BinaryChecksum":"0843e92328c0fb62c02212ed103edb4d"}},"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJjaGlsZCBIZWxsbyBXb3JsZCI=","header":""}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.8345687Z"}
2021/01/12 15:29:11 DEBUG [] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9003,"command":"ExecuteActivity","options":{"name":"SimpleActivity.echo","options":{"TaskQueueName":null,"ScheduleToCloseTimeout":0,"ScheduleToStartTimeout":0,"StartToCloseTimeout":5000000000,"HeartbeatTimeout":0,"WaitForCancellation":false,"ActivityID":"","RetryPolicy":{"initial_interval":null,"backoff_coefficient":2,"maximum_interval":null,"maximum_attempts":2,"non_retryable_error_types":[]}}},"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJjaGlsZCBIZWxsbyBXb3JsZCI=","header":""},{"payloads":"ChkKFwoIZW5jb2RpbmcSC2JpbmFyeS9udWxs"}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9003,"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJDSElMRCBIRUxMTyBXT1JMRCI="}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.8915616Z"}
2021/01/12 15:29:11 DEBUG [{"id":9004,"command":"CompleteWorkflow","options":{},"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJDSElMRCBIRUxMTyBXT1JMRCI=","header":""}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9004,"payloads":"CiUKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SCyJjb21wbGV0ZWQi"},{"command":"DestroyWorkflow","options":{"runId":"432081db-dd2e-4865-9407-e3c3f95f2e74"}}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.8915616Z","replay":true}
2021/01/12 15:29:11 DEBUG [{"payloads":"ChkKFwoIZW5jb2RpbmcSC2JpbmFyeS9udWxs"}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9001,"payloads":"Ci0KFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SEyJDSElMRCBIRUxMTyBXT1JMRCI="}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.9169058Z"}
2021/01/12 15:29:11 DEBUG [{"id":9005,"command":"CompleteWorkflow","options":{},"payloads":"CjQKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SGiJDaGlsZDogQ0hJTEQgSEVMTE8gV09STEQi","header":""}] {"receive": true}
2021/01/12 15:29:11 DEBUG [{"id":9005,"payloads":"CiUKFgoIZW5jb2RpbmcSCmpzb24vcGxhaW4SCyJjb21wbGV0ZWQi"},{"command":"DestroyWorkflow","options":{"runId":"eede8d74-cabb-4c49-bd0d-b87f14306d33"}}] {"taskQueue":"default","tickTime":"2021-01-12T15:29:11.9169058Z","replay":true}
2021/01/12 15:29:11 DEBUG [{"payloads":"ChkKFwoIZW5jb2RpbmcSC2JpbmFyeS9udWxs"}] {"receive": true}
10 changes: 10 additions & 0 deletions tests/Functional/WorkflowTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ public function testExecuteChildWorkflowNamespaced(): void
$worker->run($this, Splitter::create('Test_ExecuteChildWorkflowNamespaced.log')->getQueue());
}

/**
* Namespace must be inherited by default
*/
public function testExecuteChildWorkflowTaskQueueInheritance(): void
{
$worker = WorkerMock::createMock();

$worker->run($this, Splitter::create('Test_ExecuteChildWorkflowTaskQueue.log')->getQueue());
}

public function testRuntimeSignal(): void
{
$worker = WorkerMock::createMock();
Expand Down
36 changes: 25 additions & 11 deletions tests/worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
use Temporal\Tests\Fixtures\PipelineProvider;
use Temporal\Tests\Interceptor\HeaderChanger;
use Temporal\Tests\Interceptor\InterceptorCallsCounter;
use Temporal\Worker\WorkerInterface;

require __DIR__ . '/../vendor/autoload.php';

/**
* @param string $dir
* @return array<string>
* @return array<class-string>
*/
$getClasses = static function (string $dir, string $namespace): iterable {
$dir = realpath($dir);
Expand All @@ -41,24 +42,37 @@
HeaderChanger::class,
];

$worker = $factory->newWorker(
'default',
\Temporal\Worker\WorkerOptions::new()
->withMaxConcurrentWorkflowTaskPollers(5),
interceptorProvider: new PipelineProvider($interceptors),
);
$workers = [
'default' => $factory->newWorker(
'default',
\Temporal\Worker\WorkerOptions::new()
->withMaxConcurrentWorkflowTaskPollers(5),
interceptorProvider: new PipelineProvider($interceptors),
),
'FooBar' => $factory->newWorker(
'FooBar',
\Temporal\Worker\WorkerOptions::new()
->withMaxConcurrentWorkflowTaskPollers(5),
),
];

// register all workflows
foreach ($getClasses(__DIR__ . '/Fixtures/src/Workflow', 'Temporal\\Tests\\Workflow\\') as $class) {
if (class_exists($class) && !interface_exists($class)) {
$worker->registerWorkflowTypes($class);
if (class_exists($class) && !\interface_exists($class)) {
\array_walk(
$workers,
static fn (WorkerInterface $worker) => $worker->registerWorkflowTypes($class),
);
}
}

// register all activity
foreach ($getClasses(__DIR__ . '/Fixtures/src/Activity', 'Temporal\\Tests\\Activity\\') as $class) {
if (class_exists($class) && !interface_exists($class)) {
$worker->registerActivityImplementations(new $class());
if (class_exists($class) && !\interface_exists($class)) {
\array_walk(
$workers,
static fn (WorkerInterface $worker) => $worker->registerActivityImplementations(new $class()),
);
}
}

Expand Down

0 comments on commit cc87986

Please sign in to comment.