Skip to content
Snippets Groups Projects

Dev

Merged Chris Hines requested to merge dev into test
2 files
+ 176
67
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 43
25
@@ -4,9 +4,9 @@ import { ComputesitesService } from './computesites.service';
@@ -4,9 +4,9 @@ import { ComputesitesService } from './computesites.service';
import { AuthorisationService } from './authorisation.service';
import { AuthorisationService } from './authorisation.service';
import { Job } from './job';
import { Job } from './job';
import { Identity } from './identity';
import { Identity } from './identity';
import { Subscription, interval, pipe, Observable } from 'rxjs';
import { Subscription, interval, pipe, Observable, throwError, of } from 'rxjs';
import { BehaviorSubject, timer } from 'rxjs';
import { BehaviorSubject, timer } from 'rxjs';
import { repeat } from 'rxjs/operators';
import { repeatWhen, delay, tap, catchError } from 'rxjs/operators';
import { NotificationsService } from './notifications.service';
import { NotificationsService } from './notifications.service';
@@ -24,10 +24,11 @@ export class JobsService {
@@ -24,10 +24,11 @@ export class JobsService {
public setId(id: Identity) {
public setId(id: Identity) {
this.id = id;
this.id = id;
if (this.tsub !== undefined) {
// if (this.tsub !== undefined) {
this.tsub.unsubscribe()
// this.tsub.unsubscribe()
}
// }
this.tsub = timer(5000).pipe(repeat()).subscribe(() => this.refreshJobs())
//this.tsub = timer(5000).pipe(repeat()).subscribe(() => this.refreshJobs())
 
this.refreshJobs()
}
}
public refreshJobs() {
public refreshJobs() {
@@ -35,34 +36,51 @@ export class JobsService {
@@ -35,34 +36,51 @@ export class JobsService {
var query$: Observable<Job[]>;
var query$: Observable<Job[]>;
console.log('refreshJobs');
console.log('refreshJobs');
query$ = this.tes.runCommand(this.id, this.id.site.statcmd)
query$ = this.tes.runCommand(this.id, this.id.site.statcmd)
query$.subscribe((qjobs) => this.jobs$.next(<Job[]>qjobs),
//query$.subscribe((qjobs) => this.jobs$.next(<Job[]>qjobs),
 
// (error) => this.getJobsError(error,this.id))
 
query$.pipe(
 
repeatWhen(x => x.pipe(delay(5000))),
 
catchError((err) => this.getJobsErrorHandler(err, this.id.site.statcmd, this.id)),
 
tap((_) => console.log('in refreshJobs' + Date())),
 
).subscribe((qjobs) => this.jobs$.next(<Job[]>qjobs),
(error) => this.getJobsError(error,this.id))
(error) => this.getJobsError(error,this.id))
}
}
}
}
public getJobsError(error,identity: Identity) {
public getJobsErrorHandler(error, cmd: string, identity: Identity): Observable<any> {
if (error.hasOwnProperty('status') && error.status == 401) {
var emsg: string = "";
this.notifications.notify("Your login appears to have expired. Please log in again", () => { this.authService.updateAgentContents().subscribe((_) => {return}) } );
if (error.hasOwnProperty('error') && error.error.hasOwnProperty('message') ) {
return;
emsg = error.error.message;
 
} else {
 
emsg = error.message;
 
}
 
if (identity.expiry < Date.now() || (error.hasOwnProperty("status") && error.status == 401)) {
 
this.notifications.notify("Your login has expired. Please log in again", () => { this.authService.updateAgentContents().subscribe( () => {return} ) } );
 
return throwError(error);
 
}
 
 
if (error.hasOwnProperty("status") && error.status == 500) {
 
this.notifications.notify("The Strudel2 API server had an error.\n Please report this via the contact us link.\nThe error message was"+emsg);
 
return of([]);
}
}
this.tsub.unsubscribe();
if (error.hasOwnProperty("status") && error.status == 400) {
if (identity.expiry < Date.now()) {
this.notifications.notify(cmd + " unexpectedly returned an error message.\n Please report this vai the contact us link.\nThe error message was\n" + emsg);
this.notifications.notify("Your login has expired. Please log in again", () => { this.authService.updateAgentContents().subscribe((_) => {return}) } );
return throwError(error);
return;
}
}
console.error('getJobsError id', identity);
if (error.hasOwnProperty("status") && error.status == 504) {
if (error.hasOwnProperty("error") && error.error.hasOwnProperty("message")) {
this.notifications.notify("The Server timed out while retrieveing a list of running jobs. Is the application server OK?");
if (error.error.message.indexOf("Permission denied") != -1) {
return of([]);
this.notifications.notify("Your login appears to have expired. Please log in again", () => { this.authService.updateAgentContents().subscribe((_) => {return}) } );
return;
}
this.notifications.notify("Unable to retrieve a list of running jobs.\nThe error messge was " + error.error.message);
console.log(error);
return;
}
}
 
if (error.error instanceof ErrorEvent) {
 
this.notifications.notify("A networking error occured. Is your internet connection OK?")
 
return throwError(error);
 
}
 
}
 
 
public getJobsError(error,identity: Identity) {
console.error(error);
console.error(error);
this.notifications.notify("Unable to retrieve a list of running jobs.\nThe error wasn't specified\nPlease report what you were doign via the contact us link", () => { this.authService.updateAgentContents().subscribe((_) => {return}) });
this.notifications.notify("Unable to retrieve a list of running jobs.\nThis is probably an error on our end.\nPlease report what you were doing via the contact us link", () => { this.authService.updateAgentContents().subscribe((_) => {return}) });
//this.authService.updateAgentContents().subscribe((_) => {return});
//this.authService.updateAgentContents().subscribe((_) => {return});
}
}
Loading