Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions projects/dashboard-core/src/lib/models/edc-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>;
}
23 changes: 22 additions & 1 deletion projects/dashboard-core/src/lib/services/edc-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class EdcClientService implements OnDestroy {
*/
private healthCheckInterval = 30;

private currentConfig?: EdcConfig;

private readonly _client = new BehaviorSubject<EdcConnectorClient | undefined>(undefined);
private readonly _isHealthy: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
readonly isHealthy$ = this._isHealthy.asObservable();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -151,5 +171,6 @@ export class EdcClientService implements OnDestroy {
this._client.complete();
this._isHealthy.complete();
this.stopHealthCheckJob();
this.currentConfig = undefined;
}
}
Loading