Skip to content

Commit

Permalink
Remove enketo polling in Form Show (#987)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktuite authored May 1, 2024
1 parent bd2581a commit ed5162b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 461 deletions.
71 changes: 2 additions & 69 deletions src/components/form/show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ except according to the terms contained in the LICENSE file.
</template>

<script>
import { DateTime } from 'luxon';

import FormHead from './head.vue';
import Loading from '../loading.vue';
import PageBody from '../page/body.vue';

import useCallWait from '../../composables/call-wait';
import useForm from '../../request-data/form';
import useDatasets from '../../request-data/datasets';
import useRequest from '../../composables/request';
Expand Down Expand Up @@ -59,12 +56,11 @@ export default {
useDatasets();

const { request, awaitingResponse } = useRequest();
const { callWait, cancelCall } = useCallWait();
const { formPath } = useRoutes();
return {
project, form, formDraft, attachments,
...resourceStates([project, form, formDraft, attachments]),
request, awaitingResponse, callWait, cancelCall, formPath
request, awaitingResponse, formPath
};
},
created() {
Expand All @@ -78,82 +74,19 @@ export default {
resend
}).catch(noop);
},
// Wait for up to a total of 10 minutes, not including request time.
waitToRequestEnketoId(tries) {
if (tries < 20) return 3000;
if (tries < 50) return 8000;
if (tries < 70) return 15000;
return null;
},
fetchForm() {
this.cancelCall('fetchEnketoIdsForForm');
const url = apiPaths.form(this.projectId, this.xmlFormId);
this.form.request({ url, extended: true })
.then(() => {
if (this.form.publishedAt == null) return;
this.callWait(
'fetchEnketoIdsForForm',
async () => {
if (this.form.enketoId != null && this.form.enketoOnceId != null)
return true;
// If Enketo hasn't finished processing the form in 15 minutes,
// something else has probably gone wrong.
if (Date.now() -
DateTime.fromISO(this.form.publishedAt).toMillis() > 900000)
return true;
await this.form.request({
url,
patch: ({ data }) => {
this.form.enketoId = data.enketoId;
this.form.enketoOnceId = data.enketoOnceId;
},
alert: false
});
// The next call will check whether the form now has both Enketo
// IDs.
return false;
},
this.waitToRequestEnketoId
);
})
.catch(noop);
},
fetchDraft() {
this.cancelCall('fetchEnketoIdForDraft');
const draftUrl = apiPaths.formDraft(this.projectId, this.xmlFormId);
Promise.allSettled([
this.formDraft.request({
url: draftUrl,
extended: true,
fulfillProblem: ({ code }) => code === 404.1
})
.then(() => {
this.callWait(
'fetchEnketoIdForDraft',
async () => {
if (this.formDraft.isEmpty() ||
this.formDraft.get().enketoId != null)
return true;
await this.formDraft.request({
url: draftUrl,
patch: ({ data }) => {
// Do nothing if the form draft has been set to
// Option.none() after a different, concurrent request, for
// example, after the draft is published.
if (this.formDraft.isDefined()) {
// We do not check that the draft has not changed, for
// example, by another user concurrently modifying the
// draft.
this.formDraft.get().enketoId = data.enketoId;
}
},
alert: false
});
return false;
},
this.waitToRequestEnketoId
);
}),
}),
this.attachments.request({
url: apiPaths.formDraftAttachments(this.projectId, this.xmlFormId),
fulfillProblem: ({ code }) => code === 404.1
Expand Down
Loading

0 comments on commit ed5162b

Please sign in to comment.