Skip to content

Commit

Permalink
make sure background jobs status is updated every minute.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Oct 9, 2023
1 parent c1f057a commit bbf5169
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
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

constructor(public fastenApi: FastenApiService, private modalService: NgbModal) { }


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) {
Expand Down

0 comments on commit bbf5169

Please sign in to comment.