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
+ 42
26
@@ -4,9 +4,9 @@ import { ComputesitesService } from './computesites.service';
import { AuthorisationService } from './authorisation.service';
import { Job } from './job';
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 { repeat } from 'rxjs/operators';
import { repeatWhen, delay, tap, catchError } from 'rxjs/operators';
import { NotificationsService } from './notifications.service';
@@ -24,45 +24,61 @@ export class JobsService {
public setId(id: Identity) {
this.id = id;
if (this.tsub !== undefined) {
this.tsub.unsubscribe()
}
this.tsub = timer(5000).pipe(repeat()).subscribe(() => this.refreshJobs())
// if (this.tsub !== undefined) {
// this.tsub.unsubscribe()
// }
//this.tsub = timer(5000).pipe(repeat()).subscribe(() => this.refreshJobs())
this.refreshJobs()
}
public refreshJobs() {
if (this.id !== undefined && this.id !== null) {
var query$: Observable<Job[]>;
console.log('refreshJobs');
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)),
).subscribe((qjobs) => this.jobs$.next(<Job[]>qjobs),
(error) => this.getJobsError(error,this.id))
}
}
public getJobsError(error,identity: Identity) {
if (error.hasOwnProperty('status') && error.status == 401) {
this.notifications.notify("Your login appears to have expired. Please log in again", () => { this.authService.updateAgentContents().subscribe((_) => {return}) } );
return;
public getJobsErrorHandler(error, cmd: string, identity: Identity): Observable<any> {
var emsg: string = "";
if (error.hasOwnProperty('error') && error.error.hasOwnProperty('message') ) {
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 (identity.expiry < Date.now()) {
this.notifications.notify("Your login has expired. Please log in again", () => { this.authService.updateAgentContents().subscribe((_) => {return}) } );
return;
if (error.hasOwnProperty("status") && error.status == 400) {
this.notifications.notify(cmd + " unexpectedly returned an error message.\n Please report this vai the contact us link.\nThe error message was\n" + emsg);
return throwError(error);
}
console.error('getJobsError id', identity);
if (error.hasOwnProperty("error") && error.error.hasOwnProperty("message")) {
if (error.error.message.indexOf("Permission denied") != -1) {
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.hasOwnProperty("status") && error.status == 504) {
this.notifications.notify("The Server timed out while retrieveing a list of running jobs. Is the application server OK?");
return of([]);
}
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);
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});
}
Loading