|
7 | 7 | use Gplanchat\Bridge\Temporal\Store\TaskQueuePollers; |
8 | 8 | use Gplanchat\Durable\Observation\BackendHealth; |
9 | 9 | use Gplanchat\Durable\Observation\RunDashboard; |
| 10 | +use Gplanchat\Durable\Observation\WorkflowRunDescription; |
| 11 | +use Gplanchat\Durable\Observation\WorkflowRunPage; |
10 | 12 | use Gplanchat\DurableModule\Runtime\RuntimeFactory; |
11 | 13 | use Magento\Backend\Block\Template; |
12 | 14 | use Magento\Backend\Block\Template\Context; |
@@ -42,6 +44,8 @@ class ProcessHistory extends Template |
42 | 44 | /** @var array<string, int>|null */ |
43 | 45 | private ?array $counters = null; |
44 | 46 |
|
| 47 | + private ?WorkflowRunPage $page = null; |
| 48 | + |
45 | 49 | public function __construct( |
46 | 50 | Context $context, |
47 | 51 | private readonly RuntimeFactory $runtimeFactory, |
@@ -96,13 +100,25 @@ public function isReachable(): bool |
96 | 100 | */ |
97 | 101 | public function getCounters(): array |
98 | 102 | { |
99 | | - if ($this->counters === null) { |
100 | | - $this->counters = RunDashboard::outcomeCounters( |
101 | | - $this->runtimeFactory->catalog()->listRuns(limit: RuntimeFactory::OBSERVATION_WINDOW)->runs, |
102 | | - ); |
103 | | - } |
| 103 | + return $this->counters ??= RunDashboard::outcomeCounters($this->page()->runs); |
| 104 | + } |
104 | 105 |
|
105 | | - return $this->counters; |
| 106 | + /** |
| 107 | + * How many of the window's runs no worker has picked up (#818): a subset of the running ones, |
| 108 | + * `null` when the backend cannot tell, since zero would claim that none waits. |
| 109 | + */ |
| 110 | + public function getWaitingForWorker(): ?int |
| 111 | + { |
| 112 | + $page = $this->page(); |
| 113 | + |
| 114 | + return $page->tellsWaitingForWorker |
| 115 | + ? \count(array_filter($page->runs, static fn(WorkflowRunDescription $run): bool => null !== $run->waitingForWorkerSince)) |
| 116 | + : null; |
| 117 | + } |
| 118 | + |
| 119 | + private function page(): WorkflowRunPage |
| 120 | + { |
| 121 | + return $this->page ??= $this->runtimeFactory->catalog()->listRuns(limit: RuntimeFactory::OBSERVATION_WINDOW); |
106 | 122 | } |
107 | 123 |
|
108 | 124 | public function getWindow(): int |
|
0 commit comments