Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a cancel button for annotation workers #690

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/components/AnnotationWorkerMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@
<v-row>
<v-btn @click="preview">preview</v-btn>
<v-spacer></v-spacer>
<v-btn @click="compute" :disabled="running">
<v-progress-circular size="16" v-if="running" indeterminate />
<v-btn @click="compute" v-if="!running">
<v-icon v-if="previousRunStatus === false">mdi-close</v-icon>
<v-icon v-if="previousRunStatus === true">mdi-check</v-icon>
<span>Compute</span>
</v-btn>
<v-btn v-else @click="cancel" color="orange" :disabled="!currentJob">
<v-progress-circular size="16" indeterminate />
<span>Cancel</span>
</v-btn>
</v-row>
<v-row>
<v-checkbox
Expand All @@ -60,6 +63,7 @@ import { Vue, Component, Watch, Prop } from "vue-property-decorator";
import store from "@/store";
import annotationsStore from "@/store/annotation";
import {
IComputeJob,
IProgressInfo,
IToolConfiguration,
IWorkerInterfaceValues,
Expand All @@ -83,6 +87,7 @@ export default class AnnotationWorkerMenu extends Vue {

fetchingWorkerInterface: boolean = false;
running: boolean = false;
currentJob: IComputeJob | null = null;
previousRunStatus: boolean | null = null;
progressInfo: IProgressInfo = {};

Expand Down Expand Up @@ -116,13 +121,14 @@ export default class AnnotationWorkerMenu extends Vue {
this.propertyStore.setDisplayWorkerPreview(value);
}

compute() {
async compute() {
if (this.running) {
return;
}
this.running = true;
this.currentJob = null;
this.previousRunStatus = null;
this.annotationsStore.computeAnnotationsWithWorker({
this.currentJob = await this.annotationsStore.computeAnnotationsWithWorker({
tool: this.tool,
workerInterface: this.interfaceValues,
progress: this.progressInfo,
Expand All @@ -134,6 +140,14 @@ export default class AnnotationWorkerMenu extends Vue {
});
}

cancel() {
const jobId = this.currentJob?.jobId;
if (!jobId) {
return;
}
this.store.api.cancelJob(jobId);
}

preview() {
this.propertyStore.requestWorkerPreview({
image: this.image,
Expand Down
4 changes: 4 additions & 0 deletions src/store/GirderAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ export default class GirderAPI {
});
}

cancelJob(jobId: string) {
return this.client.put(`/job/${jobId}/cancel`);
}

async scheduleHistogramCache(datasetId: string) {
const largeImageItems = await this.getImages(datasetId);
const responses = [];
Expand Down
2 changes: 2 additions & 0 deletions src/store/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ export class Annotations extends VuexModule {
callback: (success: boolean) => void;
}) {
if (!main.dataset || !main.configuration) {
callback(false);
return null;
}
const datasetId = main.dataset.id;
Expand All @@ -723,6 +724,7 @@ export class Annotations extends VuexModule {
// Keep track of running jobs
const jobId = response.data[0]?._id;
if (!jobId) {
callback(false);
return null;
}
const computeJob: IComputeJob = {
Expand Down
Loading