Skip to content

Commit

Permalink
watching the job watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Jul 12, 2023
1 parent 0af58df commit 9f85c4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
16 changes: 6 additions & 10 deletions ui/app/controllers/jobs/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,17 @@ export default class JobController extends Controller {
return this.model;
}

get jobNotFoundFromServer() {
return (
this.watchers.job.isError &&
this.watchers.job.error.errors?.some((e) => e.status === '404')
);
}

@action notFoundJobHandler() {
if (this.jobNotFoundFromServer) {
if (
this.watchers.job.isError &&
this.watchers.job.error?.errors?.some((e) => e.status === '404')
) {
this.notifications.add({
title: `Job ${this.job.name} has been deleted`,
title: `Job "${this.job.name}" has been deleted`,
message:
'The job you were looking at has been deleted; this is usually because it was purged from elsewhere.',
color: 'critical',
destroyOnClick: false,
sticky: true,
});
this.router.transitionTo('jobs');
}
Expand Down
3 changes: 3 additions & 0 deletions ui/app/routes/jobs/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import RSVP from 'rsvp';
import notifyError from 'nomad-ui/utils/notify-error';
import classic from 'ember-classic-decorator';
import { watchRecord } from 'nomad-ui/utils/properties/watch';
import { collect } from '@ember/object/computed';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

@classic
Expand Down Expand Up @@ -71,4 +72,6 @@ export default class JobRoute extends Route.extend(WithWatchers) {
}

@watchRecord('job', { shouldSurfaceErrors: true }) watch;
@collect('watch')
watchers;
}
2 changes: 1 addition & 1 deletion ui/app/templates/jobs/job.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
SPDX-License-Identifier: MPL-2.0
~}}

{{did-update this.notFoundJobHandler this.jobNotFoundFromServer}}
{{did-update this.notFoundJobHandler this.watchers.job.isError}}
<Breadcrumb @crumb={{hash type="job" job=this.job}} />{{outlet}}

0 comments on commit 9f85c4a

Please sign in to comment.