简体   繁体   English

Google Apps脚本的执行超时

[英]Execution Timeout for Google Apps Script

I'm currently writing a script that copies a folder, and all of its sub-folders and files of a very large directory from one location in Google Drive to another. 我目前正在编写一个脚本,用于将文件夹及其所有子文件夹和非常大目录的文件从Google云端硬盘中的一个位置复制到另一个位置。 This is being used for archiving purposes for the company which I am employed by. 这正用于我受雇的公司的存档目的。

My issue is that the size and quantity of the file that I am trying to archive is WAY too large to handle in the 5 minute execution time given by Google. 我的问题是,我要归档的文件大小和数量太大,无法在Google给定的5分钟执行时间内处理。 I am trying to keep this script as a standalone web app, however I am happy to extend on it as needed. 我正在尝试将此脚本保留为独立的Web应用程序,但是我很高兴根据需要对其进行扩展。

My second issue is that I need the script to run over and over again until the folders have been copied but once it is finished I need it to stop. 我的第二个问题是,我需要一遍又一遍地运行脚本,直到复制完文件夹为止,但是一旦完成,我就需要停止脚本。 I was originally going to use triggers, however time-based triggers are inappropriate for the task I am trying to fulfil. 我本来打算使用触发器,但是基于时间的触发器不适用于我要完成的任务。

In short, I need my script to run until the task is completed, automatically restarting itself, and avoiding execution time errors. 简而言之,我需要运行脚本直到任务完成,然后自动重新启动自身并避免执行时间错误。

The full code is included below. 完整的代码包含在下面。

//Global Variables
var classroomFolderName = "Classroom";
var archiveFolderName = "Archive";

function doGet(){
  var classroomFolder = DriveApp.getFoldersByName(classroomFolderName).next();
  var archiveFolder = DriveApp.getFoldersByName(archiveFolderName).next();

  start(archiveFolder);
}

function getFolder(folderName){
  var foldercount = 0;
  //Selects all folders named exactally as parameter is given
  var folder = DriveApp.getFoldersByName(folderName);
  while (folder.hasNext()) {
    var folders = folder.next();
    foldercount++;
  }

  //Throws errors if number of folders != 1
  if (foldercount < 1){
    throw 1;
  }

  else if (foldercount > 1){
    throw 2;
  }

  else{
    return folder;
  }
}

function start(archiveFolder) {

  var sourceFolder = classroomFolderName;
  var targetFolder = "New Archive";

  var source = DriveApp.getFoldersByName(sourceFolder);
  var target = archiveFolder.createFolder(targetFolder);

  if (source.hasNext()) {
    copyFolder(source.next(), target);
  }

}

function copyFolder(source, target) {

  var folders = source.getFolders();
  var files   = source.getFiles();

  while(files.hasNext()) {
    var file = files.next();
    file.makeCopy(file.getName(), target);
  }

  while(folders.hasNext()) {
    var subFolder = folders.next();
    var folderName = subFolder.getName();
    var targetFolder = target.createFolder(folderName);
    copyFolder(subFolder, targetFolder);
  }  

}

This is something I came across- you may find some value in it- 这是我遇到的事情-您可能会发现其中的一些价值-

https://ctrlq.org/code/20016-maximum-execution-time-limit https://ctrlq.org/code/20016-maximum-execution-time-limit

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

相关问题 Google Apps 脚本最长执行时间问题 - Problem with Google Apps Script maximum execution time 如何减少此脚本的执行时间(Google应用脚本超时) - How to reduce execution time of this script (Google app script timeout) PHP脚本执行超时 - php script execution timeout 加快执行数组操作Google Apps脚本的速度 - Speed up execution of array manipulating Google Apps Script Google Apps 脚本 - 避免 doPost 同时执行限制 - Google Apps Script - Avoiding doPost Simultaneous Execution Limits 谷歌应用脚本超过最大执行时间问题 - Google apps script Exceeded maximum execution time issue 触发器执行和编辑器执行的 Google Apps 脚本执行超时是否不同? - Are Google Apps Script execution timeouts different for trigger executions and editor executions? 通过 API 密钥和 Javascript 使用 Google Apps Script Execution API - Use Google Apps Script Execution API with API keys and Javascript 锁定Google Apps脚本执行,直到替换文本为止 - Lock Google Apps script execution until text has been replaced 如何在此Google Apps脚本中更改执行流程和函数调用? - How to change the flow of execution and function call in this Google Apps Script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM