Skip to content

Commit

Permalink
UI handles 502s and 504s gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Jun 24, 2024
1 parent cc7a5ed commit b532512
Show file tree
Hide file tree
Showing 4 changed files with 405 additions and 315 deletions.
73 changes: 73 additions & 0 deletions ui/app/controllers/jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class JobsIndexController extends Controller {
@service store;
@service userSettings;
@service watchList;
@service notifications;

@tracked pageSize;

Expand Down Expand Up @@ -156,12 +157,72 @@ export default class JobsIndexController extends Controller {
);
}

/**
* In case the user wants to specifically stop polling for new jobs
*/
@action pauseJobFetching() {
// this.showingCachedJobs = false;
let notification = this.notifications.queue.find(
(n) => n.title === 'Error fetching jobs'
);
if (notification) {
notification.destroyMessage();
}
this.watchList.jobsIndexIDsController.abort();
this.watchList.jobsIndexDetailsController.abort();
this.watchJobIDs.cancelAll();
this.watchJobs.cancelAll();
}

@action restartJobList() {
this.showingCachedJobs = false;
let notification = this.notifications.queue.find(
(n) => n.title === 'Error fetching jobs'
);
if (notification) {
notification.destroyMessage();
}
this.watchList.jobsIndexIDsController.abort();
this.watchList.jobsIndexDetailsController.abort();
this.watchJobIDs.cancelAll();
this.watchJobs.cancelAll();
this.watchJobIDs.perform({}, JOB_LIST_THROTTLE);
this.watchJobs.perform(this.jobIDs, JOB_DETAILS_THROTTLE);
}

@localStorageProperty('nomadLiveUpdateJobsIndex', true) liveUpdatesEnabled;

// #endregion pagination

//#region querying

/**
*
* Let the user know that there was difficulty fetching jobs, but don't overload their screen with notifications.
* Set showingCachedJobs to tell the template to prompt them to extend timeouts
* @param {Error} e
*/
notifyFetchError(e) {
const firstError = e.errors[0];
console.log('firstError', firstError);
this.notifications.add({
title: 'Error fetching jobs',
message: `The backend returned an error with status ${firstError.status} while fetching jobs`,
color: 'critical',
sticky: true,
preventDuplicates: true,
});
// Specific check for a proxy timeout error
if (
!this.showingCachedJobs &&
(firstError.status === '502' || firstError.status === '504')
) {
this.showingCachedJobs = true;
}
}

@tracked showingCachedJobs = false;

jobQuery(params) {
this.watchList.jobsIndexIDsController.abort();
this.watchList.jobsIndexIDsController = new AbortController();
Expand All @@ -172,9 +233,17 @@ export default class JobsIndexController extends Controller {
abortController: this.watchList.jobsIndexIDsController,
},
})
.then((jobs) => {
this.showingCachedJobs = false;
return jobs;
})
.catch((e) => {
if (e.name !== 'AbortError') {
console.log('error fetching job ids', e);
this.notifyFetchError(e);
}
if (this.jobs.length) {
return this.jobs;
}
return;
});
Expand All @@ -194,6 +263,10 @@ export default class JobsIndexController extends Controller {
.catch((e) => {
if (e.name !== 'AbortError') {
console.log('error fetching job allocs', e);
this.notifyFetchError(e);
}
if (this.jobs.length) {
return this.jobs;
}
return;
});
Expand Down
2 changes: 2 additions & 0 deletions ui/app/routes/jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ export default class IndexRoute extends Route.extend(
});
} catch (error) {
try {
console.log('route jobs index catch try 1');
notifyForbidden(this)(error);
} catch (secondaryError) {
console.log('route jobs index catch try 2');
return this.handleErrors(error);
}
}
Expand Down
4 changes: 4 additions & 0 deletions ui/app/styles/components/jobs-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
}
}

#jobs-list-cache-warning {
margin-bottom: 1rem;
}

.status-cell {
display: flex;
gap: 0.5rem;
Expand Down
Loading

0 comments on commit b532512

Please sign in to comment.