Estoy usando Amazon Mechanical Turk para contratar a algunos trabajadores. Estoy usando vue con firebase. En firebase tengo los hits (mturk) y quiero cerrar el hit cuando el formulario se envía en mturk iframe. El problema es que a veces cierra el hit y a veces no.
public async submitAssignment() { var urlParams = new URLSearchParams(window.location.search) if (urlParams.has('assignment_id')) { this.host = urlParams.get('host') this.assignmentId = urlParams.get('assignment_id') this.workerId = urlParams.get('workerId') this.hitId = urlParams.get('hitId') const oFormObject = document.forms['mturkForm'] oFormObject.action = this.host oFormObject.elements['assignmentId'].value = this.assignmentId oFormObject.elements['workerId'].value = this.workerId oFormObject.elements['hitId'].value = this.hitId // form is not waiting for this before submitting the form await this.$store.dispatch('hits/closeHit', { hitId: this.hitId, workerId: this.workerId }) oFormObject.submit() }}
acción Vuex
const actions = { async closeHit({}, payload: any) { await db.hits .setDone(payload) .then() .catch((error) => { console.log(error) }) } }hits.ts
async setDone(payload: any) { try { return firestore.db .collection(collectionNamespace) .doc(payload.hitId) .update({ open: false, workerId: payload.workerId }) } catch (error) { console.error('Error updating document: ', error) } }Puedes usar la siguiente sintaxis
await this.$store.dispatch('hits/closeHit', { hitId: this.hitId, workerId: this.workerId }).then(() => { oFormObject.submit() })No estoy seguro de si causa su problema actual, pero este código parece un antipatrón:
const actions = { async closeHit({}, payload: any) { await db.hits .setDone(payload) .then() .catch((error) => { console.log(error) }) } } Debe await then o await , no ambos. En este momento, su then no hace nada, pero puede estar rompiendo la await .
Más simple y con más probabilidades de ser correcto:
const actions = { async closeHit({}, payload: any) { await db.hits .setDone(payload) } }