Ma77Ball commented on code in PR #5849: URL: https://github.com/apache/texera/pull/5849#discussion_r3480278123
########## frontend/src/app/common/service/deployment-version/deployment-version.service.ts: ########## @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { HttpClient } from "@angular/common/http"; +import { Injectable } from "@angular/core"; +import { Observable, Subscription, of, timer } from "rxjs"; +import { catchError, filter, map, switchMap, take } from "rxjs/operators"; +import { Version } from "../../../../environments/version"; +import { NotificationService } from "../notification/notification.service"; + +export const VERSION_MANIFEST_URL = "assets/version.json"; +export const VERSION_POLL_INTERVAL_MS = 5 * 60 * 1000; + +@Injectable({ + providedIn: "root", +}) +export class DeploymentVersionService { + private polling?: Subscription; + + constructor( + private http: HttpClient, + private notification: NotificationService + ) {} + + // True when the deployed build's buildNumber differs from the running one. + checkForUpdate(): Observable<boolean> { + return this.http.get<{ buildNumber?: string }>(VERSION_MANIFEST_URL, { params: { t: Date.now().toString() } }).pipe( + map(manifest => { + const deployed = manifest?.buildNumber; + return typeof deployed === "string" && deployed.length > 0 && deployed !== Version.buildNumber; + }), + catchError(() => of(false)) + ); + } + + // Poll until a new deployment is detected, then prompt once. Idempotent: + // a second call while already polling returns the in-flight subscription + // rather than stacking a duplicate poller (and a duplicate prompt). + start(intervalMs: number = VERSION_POLL_INTERVAL_MS): Subscription { + if (this.polling && !this.polling.closed) { + return this.polling; + } + this.polling = timer(intervalMs, intervalMs) + .pipe( + switchMap(() => this.checkForUpdate()), + filter(updated => updated), + take(1) + ) + .subscribe(() => this.promptReload()); + return this.polling; + } + + promptReload(): void { + this.notification.blank( + "New version available", + "A new version of Texera is available. Refresh the page to update.", + { nzDuration: 0 } + ); + } Review Comment: Done. `blank()` returns the `NzNotificationRef`, so clicking the notification now reloads the page (guarded with `take(1)`). Added a test for it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
