|
9 | 9 | use Workflow\V2\Enums\TaskStatus; |
10 | 10 | use Workflow\V2\Enums\TaskType; |
11 | 11 | use Workflow\V2\Support\HealthCheck; |
| 12 | +use Workflow\V2\Support\OperatorMetrics; |
12 | 13 | use Workflow\V2\Support\StandaloneWorkerVisibility; |
| 14 | +use Workflow\V2\Support\StructuralLimits; |
13 | 15 | use Workflow\V2\Support\TaskRepairPolicy; |
14 | 16 | use Workflow\V2\Models\WorkflowTask; |
15 | 17 |
|
@@ -575,15 +577,74 @@ private function queueVisibilityAlerts(array $queueVisibility): array |
575 | 577 | } |
576 | 578 |
|
577 | 579 | /** |
578 | | - * Waterline relies on the namespace-scoped v2 health snapshot contract. |
579 | | - * WorkflowPackageApiFloor asserts the required signature at boot whenever |
580 | | - * the resolved engine source is v2. |
| 580 | + * Keep Waterline compatible with both the released alpha package and the |
| 581 | + * newer workflow branch while health snapshots gain namespace scoping. |
581 | 582 | * |
582 | 583 | * @return array<string, mixed> |
583 | 584 | */ |
584 | 585 | private function snapshotForConfiguredNamespace(): array |
585 | 586 | { |
586 | | - return HealthCheck::snapshot(now(), $this->namespace()); |
| 587 | + $namespace = $this->namespace(); |
| 588 | + $now = now(); |
| 589 | + |
| 590 | + if ((new \ReflectionMethod(HealthCheck::class, 'snapshot'))->getNumberOfParameters() >= 2) { |
| 591 | + return HealthCheck::snapshot($now, $namespace); |
| 592 | + } |
| 593 | + |
| 594 | + $metrics = OperatorMetrics::snapshot($now, $namespace); |
| 595 | + $checks = [ |
| 596 | + self::invokeLegacyHealthCheck('backendCheck', $metrics['backend'] ?? []), |
| 597 | + self::invokeLegacyHealthCheck('runSummaryProjectionCheck', $metrics['projections']['run_summaries'] ?? []), |
| 598 | + self::invokeLegacyHealthCheck('selectedRunProjectionCheck', $metrics['projections'] ?? []), |
| 599 | + self::invokeLegacyHealthCheck('historyRetentionInvariantCheck', $metrics['history'] ?? []), |
| 600 | + self::invokeLegacyHealthCheck('commandContractCheck', $metrics['command_contracts'] ?? []), |
| 601 | + self::invokeLegacyHealthCheck('taskTransportCheck', $metrics['tasks'] ?? [], $metrics['backlog'] ?? []), |
| 602 | + ]; |
| 603 | + |
| 604 | + if (self::legacyHealthCheckExists('routingHealthCheck')) { |
| 605 | + $checks[] = self::invokeLegacyHealthCheck( |
| 606 | + 'routingHealthCheck', |
| 607 | + $metrics['tasks'] ?? [], |
| 608 | + $metrics['backlog'] ?? [], |
| 609 | + $metrics['matching_role'] ?? [], |
| 610 | + $metrics['workers'] ?? [], |
| 611 | + ); |
| 612 | + } |
| 613 | + |
| 614 | + $checks[] = self::invokeLegacyHealthCheck( |
| 615 | + 'durableResumePathCheck', |
| 616 | + $metrics['backlog'] ?? [], |
| 617 | + $metrics['repair'] ?? [], |
| 618 | + $metrics['runs'] ?? [], |
| 619 | + ); |
| 620 | + $checks[] = self::invokeLegacyHealthCheck('workerCompatibilityCheck', $metrics['workers'] ?? []); |
| 621 | + $checks[] = self::invokeLegacyHealthCheck('schedulerRoleCheck', $metrics['schedules'] ?? []); |
| 622 | + $checks[] = self::invokeLegacyHealthCheck('longPollWakeAccelerationCheck'); |
| 623 | + $status = self::invokeLegacyHealthCheck('status', $checks); |
| 624 | + |
| 625 | + return [ |
| 626 | + 'generated_at' => $metrics['generated_at'] ?? $now->toJSON(), |
| 627 | + 'status' => $status, |
| 628 | + 'healthy' => $status !== 'error', |
| 629 | + 'checks' => $checks, |
| 630 | + 'categories' => self::invokeLegacyHealthCheck('categorySummary', $checks), |
| 631 | + 'operator_metrics' => $metrics, |
| 632 | + 'structural_limits' => StructuralLimits::snapshot(), |
| 633 | + ]; |
| 634 | + } |
| 635 | + |
| 636 | + private static function invokeLegacyHealthCheck(string $method, mixed ...$args): mixed |
| 637 | + { |
| 638 | + return \Closure::bind( |
| 639 | + static fn (string $method, array $args): mixed => HealthCheck::$method(...$args), |
| 640 | + null, |
| 641 | + HealthCheck::class, |
| 642 | + )($method, $args); |
| 643 | + } |
| 644 | + |
| 645 | + private static function legacyHealthCheckExists(string $method): bool |
| 646 | + { |
| 647 | + return method_exists(HealthCheck::class, $method); |
587 | 648 | } |
588 | 649 |
|
589 | 650 | /** |
|
0 commit comments