From bbf5169a446a4182b82fa31c8eeb3bba24bcf864 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Mon, 9 Oct 2023 11:28:35 -0700 Subject: [PATCH] make sure background jobs status is updated every minute. --- .../background-jobs.component.ts | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/frontend/src/app/pages/background-jobs/background-jobs.component.ts b/frontend/src/app/pages/background-jobs/background-jobs.component.ts index f00badf3..ca41f2a4 100644 --- a/frontend/src/app/pages/background-jobs/background-jobs.component.ts +++ b/frontend/src/app/pages/background-jobs/background-jobs.component.ts @@ -1,13 +1,16 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, OnDestroy, OnInit} from '@angular/core'; import {FastenApiService} from '../../services/fasten-api.service'; import {BackgroundJob} from '../../models/fasten/background-job'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import {interval, Observable, Subscription, timer} from 'rxjs'; +import {mergeMap} from 'rxjs/operators'; @Component({ selector: 'app-background-jobs', templateUrl: './background-jobs.component.html', styleUrls: ['./background-jobs.component.scss'] }) -export class BackgroundJobsComponent implements OnInit { +export class BackgroundJobsComponent implements OnInit, OnDestroy { + backgroundJobsSubscription: Subscription = null backgroundJobs: BackgroundJob[] = [] selectedBackgroundJob: BackgroundJob = null @@ -15,9 +18,22 @@ export class BackgroundJobsComponent implements OnInit { ngOnInit(): void { - this.fastenApi.getBackgroundJobs().subscribe((jobs) => { - this.backgroundJobs = jobs - }) + + //update every minute + this.backgroundJobsSubscription = timer(0, 60*1000) + .pipe( + mergeMap(() => this.fastenApi.getBackgroundJobs()) + ) + .subscribe((jobs) => { + console.log("Background jobs updated") + this.backgroundJobs = jobs + }) + } + + ngOnDestroy() { + if(this.backgroundJobsSubscription){ + this.backgroundJobsSubscription.unsubscribe() + } } openModal(content, backgroundJob: BackgroundJob) {