Skip to content

Commit cee8145

Browse files
Scope selected run lookups by namespace
1 parent 980284d commit cee8145

8 files changed

Lines changed: 348 additions & 79 deletions

File tree

src/V2/Support/HealthCheck.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static function snapshot(?CarbonInterface $now = null): array
1919
self::backendCheck($metrics['backend'] ?? []),
2020
self::runSummaryProjectionCheck($metrics['projections']['run_summaries'] ?? []),
2121
self::selectedRunProjectionCheck($metrics['projections'] ?? []),
22+
self::commandContractCheck($metrics['command_contracts'] ?? []),
2223
self::taskTransportCheck($metrics['tasks'] ?? [], $metrics['backlog'] ?? []),
2324
self::durableResumePathCheck($metrics['backlog'] ?? [], $metrics['repair'] ?? []),
2425
self::workerCompatibilityCheck($metrics['workers'] ?? []),
@@ -144,6 +145,28 @@ private static function selectedRunProjectionCheck(array $projections): array
144145
);
145146
}
146147

148+
/**
149+
* @param array<string, mixed> $metrics
150+
* @return array<string, mixed>
151+
*/
152+
private static function commandContractCheck(array $metrics): array
153+
{
154+
$needed = self::integer($metrics['backfill_needed_runs'] ?? 0);
155+
156+
return self::check(
157+
'command_contract_snapshots',
158+
$needed === 0 ? 'ok' : 'warning',
159+
$needed === 0
160+
? 'WorkflowStarted command-contract snapshots are complete.'
161+
: 'Some WorkflowStarted command-contract snapshots need backfill before operators can trust command forms.',
162+
[
163+
'backfill_needed_runs' => $needed,
164+
'backfill_available_runs' => self::integer($metrics['backfill_available_runs'] ?? 0),
165+
'backfill_unavailable_runs' => self::integer($metrics['backfill_unavailable_runs'] ?? 0),
166+
],
167+
);
168+
}
169+
147170
/**
148171
* @param array<string, mixed> $tasks
149172
* @param array<string, mixed> $backlog

src/V2/Support/HistoryExport.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public static function forRun(
5757
'childLinks',
5858
]);
5959

60+
RunCommandContract::forRun($run);
61+
6062
$summary = $run->summary;
6163
$selectedRun = SelectedRunSnapshot::forRun($run);
6264
$currentRunResolution = $selectedRun['current_run'];

src/V2/Support/OperatorMetrics.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Workflow\V2\Enums\CommandOutcome;
1111
use Workflow\V2\Enums\CommandStatus;
1212
use Workflow\V2\Enums\CommandType;
13+
use Workflow\V2\Enums\HistoryEventType;
1314
use Workflow\V2\Enums\RunStatus;
1415
use Workflow\V2\Enums\TaskStatus;
1516
use Workflow\V2\Enums\TaskType;
@@ -43,6 +44,7 @@ public static function snapshot(?CarbonInterface $now = null): array
4344
'repair' => TaskRepairCandidates::snapshot($now),
4445
'starts' => self::startMetrics($now),
4546
'history' => self::historyMetrics(),
47+
'command_contracts' => self::commandContractMetrics(),
4648
'projections' => self::projectionMetrics(),
4749
'workers' => self::workerMetrics(),
4850
'backend' => BackendCapabilities::snapshot($now),
@@ -213,6 +215,51 @@ private static function historyMetrics(): array
213215
];
214216
}
215217

218+
/**
219+
* @return array<string, int>
220+
*/
221+
private static function commandContractMetrics(): array
222+
{
223+
$needed = 0;
224+
$available = 0;
225+
226+
self::runModel()::query()
227+
->whereHas('historyEvents', static function ($query): void {
228+
$query->where('event_type', HistoryEventType::WorkflowStarted->value);
229+
})
230+
->with([
231+
'historyEvents' => static function ($query): void {
232+
$query->where('event_type', HistoryEventType::WorkflowStarted->value)
233+
->orderBy('sequence');
234+
},
235+
])
236+
->chunkById(200, static function ($runs) use (&$needed, &$available): void {
237+
foreach ($runs as $run) {
238+
if (! $run instanceof WorkflowRun) {
239+
continue;
240+
}
241+
242+
$status = RunCommandContract::backfillStatus($run);
243+
244+
if (! $status['needed']) {
245+
continue;
246+
}
247+
248+
$needed++;
249+
250+
if ($status['available']) {
251+
$available++;
252+
}
253+
}
254+
});
255+
256+
return [
257+
'backfill_needed_runs' => $needed,
258+
'backfill_available_runs' => $available,
259+
'backfill_unavailable_runs' => max(0, $needed - $available),
260+
];
261+
}
262+
216263
/**
217264
* @return array<string, array<string, int|string|null>>
218265
*/

0 commit comments

Comments
 (0)