diff --git a/projects/dashboard-core/src/lib/models/edc-config.ts b/projects/dashboard-core/src/lib/models/edc-config.ts index 2d64e72a7..7e8f741a0 100644 --- a/projects/dashboard-core/src/lib/models/edc-config.ts +++ b/projects/dashboard-core/src/lib/models/edc-config.ts @@ -22,4 +22,9 @@ export interface EdcConfig { federatedCatalogEnabled: boolean; federatedCatalogUrl?: string; did?: string; + /** + * Optional custom health check. Resolves true = healthy, false = unhealthy. + * When set, this runs instead of the native observability.checkHealth(). + */ + customHealthCheck?: () => Promise; } diff --git a/projects/dashboard-core/src/lib/services/edc-client.service.ts b/projects/dashboard-core/src/lib/services/edc-client.service.ts index 1a24571e6..1ca3e16d5 100644 --- a/projects/dashboard-core/src/lib/services/edc-client.service.ts +++ b/projects/dashboard-core/src/lib/services/edc-client.service.ts @@ -33,6 +33,8 @@ export class EdcClientService implements OnDestroy { */ private healthCheckInterval = 30; + private currentConfig?: EdcConfig; + private readonly _client = new BehaviorSubject(undefined); private readonly _isHealthy: BehaviorSubject = new BehaviorSubject(false); readonly isHealthy$ = this._isHealthy.asObservable(); @@ -72,6 +74,7 @@ export class EdcClientService implements OnDestroy { * @param config.federatedCatalogUrl - (Optional) The federated catalog URL for the EDC client. */ public setDashboardClient(config: EdcConfig): void { + this.currentConfig = config; this._client.next(this.createEdcConnectorClient(config)); this.startHealthCheckJob(); @@ -113,7 +116,24 @@ export class EdcClientService implements OnDestroy { } private runHealthCheck(edcConfig?: EdcConfig): void { - if (this._client.getValue() || edcConfig) { + const config = edcConfig ?? this.currentConfig; + + // A custom health check takes precedence over the native one. + if (config?.customHealthCheck) { + config + .customHealthCheck() + .then(isHealthy => { + if (config === this.currentConfig && isHealthy !== this._isHealthy.getValue()) { + this._isHealthy.next(isHealthy); + } + }) + .catch((e: unknown) => { + if (config === this.currentConfig) { + console.error(`[${this.constructor.name}] Custom health check failed: ${(e as Error)?.message}`); + this._isHealthy.next(false); + } + }); + } else if (this._client.getValue() || edcConfig) { const client = edcConfig ? this.createEdcConnectorClient(edcConfig) : this._client.getValue(); client?.observability .checkHealth() @@ -151,5 +171,6 @@ export class EdcClientService implements OnDestroy { this._client.complete(); this._isHealthy.complete(); this.stopHealthCheckJob(); + this.currentConfig = undefined; } }