[英]How to manage 'submit' event at the same time using Google Forms
I have a Google Forms as Test, this execute a script when event submit has ocurred. 我有一个Google Forms作为测试工具,它在事件提交发生时执行脚本。 The script get the last email address from user and send an email with a messagge (test costumized score).
该脚本从用户那里获取最后一个电子邮件地址,并发送带有消息的电子邮件(测试综合得分)。
function manager(e) {
var ultimoCorreo = getUltimoCorreo();
validarPuntaje(e.response, ultimoCorreo);
}
function getUltimoCorreo() {
var rango = HOJA_CALCULO.getRange(1,2,HOJA_CALCULO.getLastRow(),1); // Rango donde se encuentran los correos en la hoja de calculo
var ultimoCorreo = rango.getCell(HOJA_CALCULO.getLastRow(),1).getValue();
return ultimoCorreo.toLowerCase(); // Convertimos el correo a minusculas por si el usuario mandó mal el correo
} }
This working OK. 这样工作还可以。 But I'm having troubles when several users send their answers at the same time.
但是当几个用户同时发送答案时,我遇到了麻烦。 For example: When 4 users send the form at the same time, the emails with score of each is sent to last email.
例如:当4个用户同时发送表单时,具有每个分数的电子邮件将发送到最后一封电子邮件。
How I can manage 'submit' event at the same time in google forms? 如何在Google表单中同时管理“提交”事件?
UPDATE: I have been seen the LockService but I don't understand how working, yet. 更新:我曾经见过LockService,但是我还不了解它是如何工作的。
Try using Lock Service and see what happens: 尝试使用锁定服务,看看会发生什么:
function manager(e) {
var hasLock,lockService,ultimoCorreo;
lockService = LockService.getScriptLock();
hasLock = lockService.tryLock(10000);
if (!hasLock) {
MailApp.sendEmail(recipient, 'Failed to process your Form submission', 'The code failed');
Logger.log('Could not obtain lock after 10 seconds.');
return;
}
ultimoCorreo = getUltimoCorreo();
validarPuntaje(e.response, ultimoCorreo);
lockService.releaseLock();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.