Skip to content

Commit 78f7bb8

Browse files
authored
Add workflow options support (#64)
1 parent 665b96a commit 78f7bb8

File tree

6 files changed

+538
-109
lines changed

6 files changed

+538
-109
lines changed

src/Internal/ServiceContainer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,29 @@ final class ServiceContainer
112112
* @param ClientInterface $client
113113
* @param ReaderInterface $reader
114114
* @param QueueInterface $queue
115+
* @param MarshallerInterface $marshaller
115116
* @param DataConverterInterface $dataConverter
116117
*/
117118
public function __construct(
118119
LoopInterface $loop,
119120
ClientInterface $client,
120121
ReaderInterface $reader,
121122
QueueInterface $queue,
123+
MarshallerInterface $marshaller,
122124
DataConverterInterface $dataConverter
123125
) {
124126
$this->loop = $loop;
125127
$this->client = $client;
126128
$this->reader = $reader;
127129
$this->queue = $queue;
130+
$this->marshaller = $marshaller;
131+
$this->dataConverter = $dataConverter;
128132

129133
$this->env = new Environment();
130134
$this->workflows = new WorkflowCollection();
131135
$this->activities = new ActivityCollection();
132136
$this->running = new ProcessCollection($client);
133137

134-
$this->dataConverter = $dataConverter;
135-
$this->marshaller = new Marshaller(new AttributeMapperFactory($this->reader));
136-
137138
$this->workflowsReader = new WorkflowReader($this->reader);
138139
$this->activitiesReader = new ActivityReader($this->reader);
139140
}
@@ -149,6 +150,7 @@ public static function fromWorker(WorkerFactory $worker): self
149150
$worker->getClient(),
150151
$worker->getReader(),
151152
$worker->getQueue(),
153+
$worker->getMarshaller(),
152154
$worker->getDataConverter()
153155
);
154156
}

src/Internal/Transport/Router/GetWorkerInfo.php

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,31 @@
1515
use Temporal\DataConverter\EncodedValues;
1616
use Temporal\Internal\Declaration\Prototype\ActivityPrototype;
1717
use Temporal\Internal\Declaration\Prototype\WorkflowPrototype;
18+
use Temporal\Internal\Marshaller\MarshallerInterface;
1819
use Temporal\Internal\Repository\RepositoryInterface;
1920
use Temporal\Worker\WorkerInterface;
2021
use Temporal\Worker\Transport\Command\RequestInterface;
2122

2223
final 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

src/Worker/Worker.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ public function __construct(
7171
$this->router = $this->createRouter();
7272
}
7373

74+
/**
75+
* @return WorkerOptions
76+
*/
77+
public function getOptions(): WorkerOptions
78+
{
79+
return $this->options;
80+
}
81+
7482
/**
7583
* @param RequestInterface $request
7684
* @param array $headers

src/Worker/WorkerInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616

1717
interface WorkerInterface
1818
{
19+
/**
20+
* Returns info about worker
21+
*
22+
* @return WorkerOptions
23+
*/
24+
public function getOptions(): WorkerOptions;
25+
1926
/**
2027
* @param class-string ...$class
2128
* @return $this

0 commit comments

Comments
 (0)