title: 'Gmail Operation not allowed' exception after multiple calls to Gmail operations; how to avoid?
body: <p>I have a script that basically searches a folder for emails received before a certain date (uses a GmailApp call for the search multiple times in one iteration) and then moves those messages to the Trash using a GmailApp call. </p>
  
  <p>My script runs based on time, so after 15 minutes it will end and just install another trigger to it a bit later. So the script will be searching and moving emails for about an hour or 1.5 hours (with multiple triggers installed). The folder in which I search gets a lot of automated emails that I don't need after a week or two, hence why i want the script. </p>
  
  <p>do you know why I would get a GmailApp exception that says Gmail does not allow that operation when I know it does? </p>
  
  <p>Is it a quota issue? I got around the runtime quota issue but I don't know what else it could be. </p>
  
  <p>I guess another question is, is there a JS function or call that will let me delete GmailThreads? </p>
  
  <p>Edit: Adding the block of code</p>
  
  <pre><code>    var num_threads = search_threads.length;
      var num_deleted = 0;
      var countGmailX = 0;
  
  //run for 15 minutes so we don't get time error
      console.info('Entering the While Loop');
  
      while (check_time(timenow)){
  
        num_threads = search_threads.length;
        GmailApp.moveThreadsToTrash(search_threads);
        countGmailX = countGmailX + 1; 
  
        num_deleted = num_deleted + 75;
  
        if (num_threads &gt; 0){
  
          search_threads = GmailApp.search(search, 0 , 75);
          countGmailX = countGmailX + 1; 
  
        } else {
          console.info('No more Threads left to delete, exiting While Loop');
          break;
        }
      }
      console.log('Exited While Loop');
      console.log('number of times GmailApp functions called: ' + countGmailX);
  
      search_threads = GmailApp.search(search, 0, 75);
      countGmailX = countGmailX + 1; 
  </code></pre>