简体   繁体   English

如何解决非 G Suite 用户的 AppScripts 执行时间问题?

[英]How to solve execution time issue of AppScripts for non-G suite users?

I have an attendance system which is working fine for G suite users (execution time is 30 minutes) but I want to make it running for all gmail users (execution time 6 minutes).我有一个对 G Suite 用户运行良好的考勤系统(执行时间为 30 分钟),但我想让它为所有 gmail 用户运行(执行时间为 6 分钟)。 When a teacher presses a specific menu at my Google Sheets page, it allows students to report their attendance from an Android App to Google Sheet for 10 minutes.当老师在我的 Google 表格页面上按下特定菜单时,它允许学生从 Android 应用程序向 Google 表格报告他们的出勤情况 10 分钟。

The whole code is working fine for G Suite Users but I want to make it for all Gmail users.整个代码适用于 G Suite 用户,但我想为所有 Gmail 用户制作它。 I tried to execute it from a regular Gmail but it shows Timed Out at the end.我尝试从常规 Gmail 执行它,但最后显示超时。

I have the following two lines of code for students to have 10 minutes to respond:我有以下两行代码让学生有 10 分钟的时间做出回应:

function refreshSheet(){

  //Few other lines of codes are here

  var val = dashboard.getRange("C6").getValue(); //C6 is a dropdown list in Sheets of "Start 1-Period" and "Start 2-Period"
  if (val == "Start 1-Period"){ ScriptApp.newTrigger("onePeriod").timeBased().after(10*60*1000).create();}
  if (val == "Start 2-Period"){ ScriptApp.newTrigger("twoPeriod").timeBased().after(10*60*1000).create();}
  
  //These few lines of codes below within the refreshSheet() should be executed after the above called trigger and its function execution.

  for (var i=0; i<students.length; i++) {
      if (students[i][0] !== '') ss.removeEditor(students[i][0].toString());
  } 
  
  protectionm.remove();  
  SpreadsheetApp.flush();
}

function onePeriod(){}

function twoPeriod(){}

I reviewed few posts here but none of them is working for me.我在这里查看了一些帖子,但没有一个对我有用。 How can I solve it?我该如何解决?

There are two things you can do:你可以做两件事:

  1. If you deploy your script as a WebApp , you can execute it as "You" - that is the user from a GSuite domain who has an execution limit of 30 min.如果您将脚本部署为WebApp ,则可以以“您”的身份执行它 - 即来自 GSuite 域的用户,执行限制为 30 分钟。

  2. Design your script in a different way.以不同的方式设计您的脚本。

  • Instead of waiting 10 minutes with Utilities.sleep() , incorporate a time-driven trigger与其使用Utilities.sleep()等待 10 分钟,不如合并一个时间驱动的触发器
  • You can do so with the trigger builder您可以使用触发器构建器执行此操作
  • This means - end the current function and specify that the continuation of the script (embedded in the second function) will start running 10 minutes later这意味着 - 结束当前的 function 并指定脚本的延续(嵌入在第二个函数中)将在 10 分钟后开始运行
  • The time inbetween will not count as execution time and will not lead to a timeout.中间的时间不会算作执行时间,也不会导致超时。

Sample:样本:

function myFirstFunction(){
// do something
//now set-up the trigger:
    ScriptApp.newTrigger("mySecondFunction").timeBased().after(10*60*1000).create();
}

// will be called after the amount of seconds specified in `after()`
function mySecondFunction(){
//now implement the rest of your code
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建 g-suite 插件或与他人共享我编写的 Appscripts? - How can I create g-suite add-ons or share Appscripts that I've written with others? G Suite开发人员中心执行清单? - G Suite Developer Hub execution list? 应用套件G套件用户的电子邮件配额 - Email quota for app scripts G suite users 批量更新用户G-suite - Bulk Update users G-suite 您能否通过升级到 G Suite 商务版将应用脚本执行时间增加到 30 分钟? - Can you increase apps script execution time to 30 minutes by upgrading to G Suite Business? G Suite Add-on 拒绝连接到驱动器? 如何解决“drive.google.com 拒绝连接”错误? - G Suite Add-on refusing to connect to drive? How to solve “drive.google.com refused to connect” error? 如何获取使用 Google Apps 脚本的 G Suite 用户列表? - How to get a list of G Suite users which are using Google Apps Script? 将用户排除在G Suite的特定组之外 - Exclude users from belonging to a particular group in G Suite 获取G Suite中给定用户列表的用户活动报告 - Getting User Activity Reports for a given list of users in G Suite 通过AppScript快速获取大量G Suite用户的用户信息 - Getting user information for a large number of G Suite users quickly with AppScript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM