Skip to content

Commit 6d379d5

Browse files
authored
Merge pull request #1043 from gplanchat/feat/magento-dashboard-waiting-for-worker
feat(magento): say when a run is waiting for a worker (#818)
2 parents 6844167 + 8294a36 commit 6d379d5

21 files changed

Lines changed: 354 additions & 27 deletions

‎documentation/user/dashboard/_index.fr.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ Les backends SQL savent le dire (DBAL sous Symfony, Illuminate sous Laravel), su
7171
colonne `picked_up_at`, ainsi que le backend en mémoire dans son propre processus. Sous Laravel,
7272
le [panneau Filament](filament/) est la liste des exécutions. Temporal ne le peut pas
7373
depuis la liste des exécutions : ni la mention ni le nombre n'y apparaissent, et Temporal UI montre les
74-
tâches en attente. La grille Magento le peut sur le backend de base de données (`resource/durable`),
75-
dont le catalogue des exécutions enregistre la prise en charge ; elle ne le peut pas sur ses deux
76-
autres backends, celui en mémoire, vide depuis l'admin, et Temporal. Voir [la procédure de mise à jour](https://github.com/gplanchat/durable-dev/blob/main/UPGRADE.md)
74+
tâches en attente. L'administration Magento montre les deux (la grille, la page de l'exécution et
75+
les compteurs) sur le backend de base de données (`resource/durable`), dont le catalogue des
76+
exécutions enregistre la prise en charge ; elle ne le peut pas sur ses deux autres backends, celui
77+
en mémoire, vide depuis l'admin, et Temporal. Voir [la procédure de mise à jour](https://github.com/gplanchat/durable-dev/blob/main/UPGRADE.md)
7778
pour ajouter la colonne à une table créée avant elle.
7879

7980
Après la première prise en charge, les backends à journal enregistrent chaque attente d'un worker

‎documentation/user/dashboard/_index.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ same page.
6767
The SQL backends can tell (DBAL on Symfony, Illuminate on Laravel), on a runs table that has the
6868
`picked_up_at` column, and so can the in-memory backend within its process. On Laravel, the
6969
[Filament panel](filament/) is the run list. Temporal cannot from the run list, so neither the
70-
line nor the count appears there; Temporal UI shows pending tasks. The Magento grid can on the
71-
database backend (`resource/durable`), whose run catalog records the pickup; it cannot on its two
72-
other backends, the in-memory one, empty from the admin, and Temporal. See
70+
line nor the count appears there; Temporal UI shows pending tasks. The Magento admin shows both
71+
(the grid, the run page and the counters) on the database backend (`resource/durable`), whose run
72+
catalog records the pickup; it cannot on its two other backends, the in-memory one, empty from the
73+
admin, and Temporal. See
7374
[Upgrading](https://github.com/gplanchat/durable-dev/blob/main/UPGRADE.md) to add the column to a
7475
table created before it existed.
7576

‎documentation/user/dashboard/magento.fr.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ processes > Process history** dans les ressources du rôle.
3333
- **L'état du backend**, daté, avec une ligne par rôle de worker (journal et activité) quand
3434
Temporal tient le [journal](../../glossary/) (les étapes enregistrées d'une exécution et leurs résultats).
3535
- **Des compteurs** par issue, sur les 200 exécutions les plus récentes, quels que soient les
36-
filtres de la grille.
36+
filtres de la grille. Sur le backend base de données, un nombre **En attente d'un worker** s'y
37+
ajoute. La grille et la page d'exécution affichent `waiting for a worker · 42 s` pour une
38+
exécution que personne n'a prise en charge.
3739
- **La grille standard de l'administration** : pagination (20 par défaut), contrôle des colonnes,
3840
et filtres sur l'issue, le nom du workflow, l'identifiant d'exécution et l'identifiant d'exécution
3941
côté backend. Les filtres texte suivent la règle des autres surfaces, parmi les exécutions de la fenêtre : le nom entier du workflow, le début de l'identifiant d'exécution et de l'identifiant de run côté backend, le tout tel que saisi. Un avis indique la fenêtre quand elle est pleine.
@@ -43,7 +45,7 @@ processes > Process history** dans les ressources du rôle.
4345

4446
## Ce qu'elle ne montre pas
4547

46-
La grille n'affiche pas `waiting for a worker`, ni en ligne ni en nombre. La fenêtre couvre 200
48+
Sur le backend Temporal, la grille n'affiche pas `waiting for a worker` : la liste des exécutions n'enregistre aucune heure de prise en charge. La fenêtre couvre 200
4749
exécutions : une exécution plus ancienne n'apparaît pas, et les compteurs ne la comptent pas non
4850
plus. Voir [Parité](../parity/).
4951

‎documentation/user/dashboard/magento.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ processes > Process history** on the role's resources.
3030

3131
- **The backend state**, dated, and one line per worker role (journal and activity) when Temporal
3232
holds the [journal](../../glossary/) (the recorded steps of an execution and their results).
33-
- **Counters** per outcome, over the 200 most recent runs, whatever the grid filters say.
33+
- **Counters** per outcome, over the 200 most recent runs, whatever the grid filters say. On the database backend, a **Waiting for a worker** count joins
34+
them. The grid and the run page show `waiting for a worker · 42 s` for a run nobody has picked
35+
up.
3436
- **The standard admin grid**: paging (20 by default), column controls, and filters on outcome,
3537
workflow name, execution id and backend run id. The text filters follow the rule of the other surfaces, among the runs of the window: the whole workflow name, the start of the execution id and of the backend run id, all as typed. A notice states the window when it is full.
3638
- **A run page**, opened from a row: the execution, its backend run, outcome, start and end dates,
@@ -39,7 +41,7 @@ processes > Process history** on the role's resources.
3941

4042
## What it does not show
4143

42-
The grid does not say `waiting for a worker`, neither as a line nor as a count. The window is 200
44+
On the Temporal backend, the grid does not say `waiting for a worker`: the run list records no pickup time. The window is 200
4345
runs: an older run does not appear, and the counters do not reach it either. See
4446
[Parity](../parity/).
4547

‎documentation/user/dashboard/parity.fr.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ surfaces diffèrent encore. Elle change quand un écart se referme.
1919
| Filtre par issue | Oui | Oui | Oui | Non |
2020
| Filtre par nom de workflow | Nom entier, là où le backend sait l'appliquer | Nom entier, dans la fenêtre | Nom entier, là où le backend sait l'appliquer | Non |
2121
| Filtre par identifiant d'exécution | Préfixe, là où le backend sait l'appliquer | Préfixe, dans la fenêtre | Préfixe, là où le backend sait l'appliquer | Non |
22-
| `waiting for a worker` | Ligne et compteur | Non | Ligne et compteur | Non |
22+
| `waiting for a worker` | Ligne et compteur | Ligne et compteur, sur le backend base de données | Ligne et compteur | Non |
2323
| `waiting on` | Liste et page de l'exécution | Liste et page de l'exécution | Liste et page de l'exécution | Section de l'exécution |
2424
| Une ligne par action | Oui | Oui, plus une table du journal | Oui | Oui |
2525
| Temps de file hachuré | Oui | Oui | Sur la frise | Oui |

‎documentation/user/dashboard/parity.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ when a gap closes.
1919
| Outcome filter | Yes | Yes | Yes | No |
2020
| Workflow name filter | Whole name, where the backend can | Whole name, within the window | Whole name, where the backend can | No |
2121
| Execution id filter | Prefix, where the backend can | Prefix, within the window | Prefix, where the backend can | No |
22-
| `waiting for a worker` | Line and counter | No | Line and counter | No |
22+
| `waiting for a worker` | Line and counter | Line and counter, on the database backend | Line and counter | No |
2323
| `waiting on` | List and run page | List and run page | List and run page | Run section |
2424
| One line per action | Yes | Yes, plus a journal table | Yes | Yes |
2525
| Hatched queue time | Yes | Yes | On the timeline | Yes |

‎src/Durable/Observation/RunDashboard.php‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ private function describe(WorkflowRunDescription $run): array
247247
// Dispatched, and no worker has taken it yet (#447). The wording is decided here, once,
248248
// for every surface (DUR049).
249249
$described['waitingForWorkerSince'] = $run->waitingForWorkerSince;
250-
$elapsed = self::elapsed($run->waitingForWorkerSince, ($this->clock ?? new SystemClock())->now());
251-
$described['waitingForWorker'] = 'waiting for a worker · ' . $elapsed;
252-
$described['localizedWaitingForWorker'] = new Message('run.waiting_for_worker', ['elapsed' => $elapsed]);
250+
$described += self::waitingForWorker($run->waitingForWorkerSince, ($this->clock ?? new SystemClock())->now());
253251
}
254252
if (null !== $run->waitingOn) {
255253
// What the run last suspended on (#324), worded once for every surface, as above.
@@ -262,6 +260,22 @@ private function describe(WorkflowRunDescription $run): array
262260
return $described;
263261
}
264262

263+
/**
264+
* The wording of a run nobody picked up, in English and as a key with its parameter, for a host
265+
* that lists runs by its own means (Magento's grid pages by offset) and still words it once.
266+
*
267+
* @return array{waitingForWorker: string, localizedWaitingForWorker: Message}
268+
*/
269+
public static function waitingForWorker(\DateTimeImmutable $since, \DateTimeImmutable $now): array
270+
{
271+
$elapsed = self::elapsed($since, $now);
272+
273+
return [
274+
'waitingForWorker' => 'waiting for a worker · ' . $elapsed,
275+
'localizedWaitingForWorker' => new Message('run.waiting_for_worker', ['elapsed' => $elapsed]),
276+
];
277+
}
278+
265279
/**
266280
* The largest whole unit: 42 s, 5 min, 2 h, 3 d.
267281
*/

‎src/DurableModule/Block/Adminhtml/ProcessDetail.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Gplanchat\Durable\Observation\WorkflowRunDescription;
1212
use Gplanchat\Durable\Port\NexusOperationCatalogInterface;
1313
use Gplanchat\DurableModule\Runtime\RuntimeFactory;
14+
use Gplanchat\DurableModule\Ui\WaitingForWorker;
1415
use Magento\Backend\Block\Template;
1516
use Magento\Backend\Block\Template\Context;
1617

@@ -121,6 +122,17 @@ public function scale(float $seconds): string
121122
return number_format($span > 0.0 ? $seconds / $span * 100.0 : 0.0, 3, '.', '');
122123
}
123124

125+
/**
126+
* The line of a run no worker has picked up (#818), or `null` when it was, or when the backend
127+
* cannot tell.
128+
*/
129+
public function getWaitingForWorker(): ?string
130+
{
131+
$run = $this->getRun();
132+
133+
return $run === null ? null : WaitingForWorker::of($run);
134+
}
135+
124136
public function formatMoment(?\DateTimeImmutable $moment): string
125137
{
126138
return $moment === null ? '—' : $moment->format('Y-m-d H:i:s');

‎src/DurableModule/Block/Adminhtml/ProcessHistory.php‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Gplanchat\Bridge\Temporal\Store\TaskQueuePollers;
88
use Gplanchat\Durable\Observation\BackendHealth;
99
use Gplanchat\Durable\Observation\RunDashboard;
10+
use Gplanchat\Durable\Observation\WorkflowRunDescription;
11+
use Gplanchat\Durable\Observation\WorkflowRunPage;
1012
use Gplanchat\DurableModule\Runtime\RuntimeFactory;
1113
use Magento\Backend\Block\Template;
1214
use Magento\Backend\Block\Template\Context;
@@ -42,6 +44,8 @@ class ProcessHistory extends Template
4244
/** @var array<string, int>|null */
4345
private ?array $counters = null;
4446

47+
private ?WorkflowRunPage $page = null;
48+
4549
public function __construct(
4650
Context $context,
4751
private readonly RuntimeFactory $runtimeFactory,
@@ -96,13 +100,25 @@ public function isReachable(): bool
96100
*/
97101
public function getCounters(): array
98102
{
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+
}
104105

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);
106122
}
107123

108124
public function getWindow(): int

‎src/DurableModule/Ui/DataProvider/ProcessListing.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Gplanchat\Durable\Observation\WorkflowRunDescription;
88
use Gplanchat\DurableModule\Runtime\RuntimeFactory;
9+
use Gplanchat\DurableModule\Ui\WaitingForWorker;
910
use Magento\Framework\Api\Filter;
1011
use Magento\Ui\DataProvider\AbstractDataProvider;
1112

@@ -84,9 +85,12 @@ public function getData(): array
8485
'ended_at' => $run->endedAt?->format('Y-m-d H:i:s') ?? self::ABSENT,
8586
// What a suspended run last waited on (#324), as the catalogue recorded it.
8687
'waiting_on' => $run->waitingOn ?? self::ABSENT,
87-
// Since when a running run waits for a worker to pick it up (#816, #818): no column
88-
// yet, the field is on the row for the one that paints it.
88+
// Since when a running run waits for a worker to pick it up (#816), and the line the
89+
// grid paints from it (#818).
8990
'waiting_for_worker_since' => $run->waitingForWorkerSince?->format('Y-m-d H:i:s') ?? self::ABSENT,
91+
// Empty when nothing waits or the backend cannot tell, as Sylius and Filament print
92+
// nothing: a dash on every row reads as "none waits".
93+
'waiting_for_worker' => WaitingForWorker::of($run) ?? '',
9094
], $window),
9195
];
9296
}

0 commit comments

Comments
 (0)