Skip to content

Commit 3c7f93a

Browse files
committed
Fix job progress polling on client
1 parent e64081c commit 3c7f93a

5 files changed

Lines changed: 26 additions & 35 deletions

File tree

client/src/stores/corpora.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const useCorpora = defineStore("corpora", () => {
5353
API.patchCorpus(metadata.uuid, metadata).finally(reload)
5454
}
5555

56+
reload()
57+
5658
return {
5759
corpora,
5860
loading,

client/src/stores/documents.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ const documents = defineStore("documents", () => {
1818
const { reload: reloadCorpora } = stores.useCorpora()
1919

2020
// Fields
21-
const loading = ref<boolean>(false)
21+
const loading = ref<boolean>()
2222
const documents = ref<DocumentMetadata[]>([])
23-
const numSourceAnnotations = computed(() => documents.value.filter((i) => i.summary?.annotations.token > 0).length)
2423
const uploading: Record<string, FileStatus> = reactive({})
2524
const uploadBusyCount = computed(() => Object.values(uploading).filter((i) => i.status === "busy").length)
2625
const uploadErrorCount = computed(() => Object.values(uploading).filter((i) => i.status === "error").length)
@@ -106,6 +105,8 @@ const documents = defineStore("documents", () => {
106105
})
107106
}
108107

108+
reload()
109+
109110
// Exports
110111
return {
111112
// Fields
@@ -116,7 +117,6 @@ const documents = defineStore("documents", () => {
116117
uploading,
117118
uploadBusyCount,
118119
uploadErrorCount,
119-
numSourceAnnotations,
120120
// Methods
121121
reload,
122122
remove,

client/src/stores/jobs.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const POLL_INTERVAL = 5000
1010
const useJobs = defineStore("jobs", () => {
1111
// Stores
1212
const corporaStore = stores.useCorpora()
13-
const documents = stores.useDocuments()
1413
const { corpusId } = storeToRefs(corporaStore)
1514

1615
// Fields
@@ -24,10 +23,14 @@ const useJobs = defineStore("jobs", () => {
2423
// Methods
2524
/** Reload the available jobs for the current corpus. */
2625
function reload(): void {
27-
documents.reload()
2826
loading.value = true
2927
API.getJobs(corpusId.value)
30-
.then((response) => (jobs.value = response.data))
28+
.then((res) => {
29+
jobs.value = res.data
30+
jobs.value
31+
.filter((j: Job) => j.progress.busy)
32+
.forEach((j: Job) => { startPolling(j.tagger.id, corpusId.value) })
33+
})
3134
.finally(() => (loading.value = false))
3235
}
3336
/** Fetch the progress for the given job. To be used within a poller. */
@@ -41,7 +44,7 @@ const useJobs = defineStore("jobs", () => {
4144
if (response.request.responseURL.includes(corporaStore.corpusId)) {
4245
// Only commit the response if it corresponds to the correct corpus
4346
// This prevents late responses overwriting responses to newer requests
44-
jobs.value[job].progress = response.data
47+
jobs.value.find((j: Job) => j.tagger.id === job).progress = response.data
4548
// Stop polling if the job is done.
4649
if (!response.data.busy) {
4750
stopPolling(job)
@@ -119,6 +122,8 @@ const useJobs = defineStore("jobs", () => {
119122
})
120123
}
121124

125+
reload()
126+
122127
// Exports
123128
return {
124129
// Fields

client/src/stores/jobselection.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import stores from "@/stores"
2-
import { type Job, SOURCE_LAYER } from "@/types/jobs"
2+
import { type Job } from "@/types/jobs"
33
import type { SelectOption } from "@/types/ui/select"
44
import { useRouteQuery } from "@vueuse/router"
55

66
/** Stores the current job selection from the <select>. Used in Evaluation & Export. */
77
const useJobSelection = defineStore("jobSelection", () => {
88
// Stores
99
const { jobs } = storeToRefs(stores.useJobs())
10-
const { reload } = stores.useJobs()
11-
const corpora = stores.useCorpora()
12-
const documentsStore = stores.useDocuments()
10+
const { corpusId } = storeToRefs(stores.useCorpora())
1311

1412
// Fields
1513
const hypothesisId = useRouteQuery<string>("hypothesis")
@@ -20,29 +18,15 @@ const useJobSelection = defineStore("jobSelection", () => {
2018
const options = computed<SelectOption[]>((): SelectOption[] =>
2119
jobs.value
2220
.filter((j: Job) => j.progress.finished > 0)
23-
.map((j: Job) => ({ value: j.tagger.id, text: formatJobString(j) })),
24-
)
25-
26-
watch(
27-
() => corpora.corpusId,
28-
() => {
29-
hypothesisId.value = undefined
30-
referenceId.value = undefined
31-
},
21+
.map((j: Job) => ({ value: j.tagger.id, text: format(j) })),
3222
)
3323

3424
/** Format as displayed in the <select> */
35-
function formatJobString(job: Job): string {
36-
const total = job.progress.total
37-
let finished = job.progress.finished
38-
if (job.tagger.id === SOURCE_LAYER) {
39-
finished = documentsStore.numSourceAnnotations
40-
return `source annotations [${finished}/${total} docs]`
41-
}
42-
return `${job.tagger.id} (${job.tagger.description}) [${finished}/${total} docs]`
25+
function format(job: Job): string {
26+
return `${job.tagger.id} (${job.tagger.description}) [${job.progress.finished}/${job.progress.total} docs]`
4327
}
4428

45-
reload()
29+
watch(corpusId, () => { hypothesisId.value = undefined; referenceId.value = undefined })
4630

4731
return { hypothesisId, referenceId, options }
4832
})

client/src/views/annotate/subviews/evaluate/subviews/DocumentLayerComparisonView.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
</GForm>
1515

1616
<div v-if="selectedDoc && selectedAnnotation" class="document">
17-
<template v-for="tc in termcomps.slice(firstRecord, firstRecord + rowsToDisplay)" :key="tc.refTerm.id">
17+
<template v-for="tc in termcomps.slice(firstRecord, firstRecord + rowsToDisplay)" :key="tc.ref.id">
1818
<span class="wordComparison" :class="{ incorrect: !annotationsEqual(tc) }">
19-
{{ tc.refTerm.annotations["token"] }}
20-
<SingleTermComparisonTable :hypoTerm="tc.hypoTerm" :refTerm="tc.refTerm" class="tooltip" />
19+
{{ tc.ref.annotations["token"] }}
20+
<SingleTermComparisonTable :hypoTerm="tc.hyp" :refTerm="tc.ref" class="tooltip" />
2121
</span>
2222

2323
<!-- add newline after . -->
24-
<br v-if="tc.refTerm.annotations['token'] == '.'" />
24+
<br v-if="tc.ref.annotations['token'] == '.'" />
2525
</template>
2626

2727
<Paginator
@@ -92,8 +92,8 @@ watch(termcomps, () => {
9292
9393
// Methods
9494
function annotationsEqual(tc: TermComparison) {
95-
const refAnnot = cleanAnnotation(tc.refTerm)
96-
const hypoAnnot = cleanAnnotation(tc.hypoTerm)
95+
const refAnnot = cleanAnnotation(tc.ref)
96+
const hypoAnnot = cleanAnnotation(tc.hyp)
9797
return refAnnot === hypoAnnot
9898
}
9999

0 commit comments

Comments
 (0)