1515use Temporal \DataConverter \EncodedValues ;
1616use Temporal \Internal \Declaration \Prototype \ActivityPrototype ;
1717use Temporal \Internal \Declaration \Prototype \WorkflowPrototype ;
18+ use Temporal \Internal \Marshaller \MarshallerInterface ;
1819use Temporal \Internal \Repository \RepositoryInterface ;
1920use Temporal \Worker \WorkerInterface ;
2021use Temporal \Worker \Transport \Command \RequestInterface ;
2122
2223final class GetWorkerInfo extends Route
2324{
25+ /**
26+ * @var RepositoryInterface
27+ */
2428 private RepositoryInterface $ queues ;
2529
30+ /**
31+ * @var MarshallerInterface
32+ */
33+ private MarshallerInterface $ marshaller ;
34+
2635 /**
2736 * @param RepositoryInterface $queues
37+ * @param MarshallerInterface $marshaller
2838 */
29- public function __construct (RepositoryInterface $ queues )
39+ public function __construct (RepositoryInterface $ queues, MarshallerInterface $ marshaller )
3040 {
3141 $ this ->queues = $ queues ;
42+ $ this ->marshaller = $ marshaller ;
3243 }
3344
3445 /**
@@ -37,6 +48,7 @@ public function __construct(RepositoryInterface $queues)
3748 public function handle (RequestInterface $ request , array $ headers , Deferred $ resolver ): void
3849 {
3950 $ result = [];
51+
4052 foreach ($ this ->queues as $ taskQueue ) {
4153 $ result [] = $ this ->workerToArray ($ taskQueue );
4254 }
@@ -45,28 +57,28 @@ public function handle(RequestInterface $request, array $headers, Deferred $reso
4557 }
4658
4759 /**
48- * @param WorkerInterface $taskQueue
60+ * @param WorkerInterface $worker
4961 * @return array
5062 */
51- private function workerToArray (WorkerInterface $ taskQueue ): array
63+ private function workerToArray (WorkerInterface $ worker ): array
5264 {
65+ $ workflowMap = function (WorkflowPrototype $ workflow ) {
66+ return [
67+ 'Name ' => $ workflow ->getID (),
68+ 'Queries ' => $ this ->keys ($ workflow ->getQueryHandlers ()),
69+ 'Signals ' => $ this ->keys ($ workflow ->getSignalHandlers ()),
70+ ];
71+ };
72+
73+ $ activityMap = static fn (ActivityPrototype $ activity ) => [
74+ 'Name ' => $ activity ->getID (),
75+ ];
76+
5377 return [
54- 'TaskQueue ' => $ taskQueue ->getID (),
55- 'Options ' => new \stdClass (), // todo: set options
56- 'Workflows ' => $ this ->map (
57- $ taskQueue ->getWorkflows (),
58- function (WorkflowPrototype $ workflow ) {
59- return [
60- 'Name ' => $ workflow ->getID (),
61- 'Queries ' => $ this ->keys ($ workflow ->getQueryHandlers ()),
62- 'Signals ' => $ this ->keys ($ workflow ->getSignalHandlers ()),
63- ];
64- }
65- ),
66- 'Activities ' => $ this ->map (
67- $ taskQueue ->getActivities (),
68- fn (ActivityPrototype $ activity ) => ['Name ' => $ activity ->getID ()]
69- ),
78+ 'TaskQueue ' => $ worker ->getID (),
79+ 'Options ' => $ this ->marshaller ->marshal ($ worker ->getOptions ()),
80+ 'Workflows ' => $ this ->map ($ worker ->getWorkflows (), $ workflowMap ),
81+ 'Activities ' => $ this ->map ($ worker ->getActivities (), $ activityMap ),
7082 ];
7183 }
7284
0 commit comments