Skip to main content

How to Suspend Execution of a Google App Script While it is Running Easy Guide!

This tutorial explains you how to Suspend Execution of a Google App Script while it is running.

Users frequently asked Mail Merge for the ability to stop the merge process (and the underlying Google Script) after pressing the start button.

Every Google Apps Script has a 5-minute maximum execution time limit, beyond which the script will immediately terminate. If you are manually executing a script from the Google Script Editor, you can click “Cancel” to stop it from running, but if the script is running through an HTML Service-powered web app or as a Google Add-on, this option is not available.

Code to Suspend Execution of a Google App Script:

Here is a little example that will demonstrate how to abruptly Suspend Execution of a Google App Script that is currently running outside of the Script Editor. The concept is to create a property that is activated when the Stop button is pushed. The currently executing script keeps an eye on this property value and pauses if it is set to “STOP”.

The HTML File

<button onclick="start()">Start</button>
<button onclick="stop()">Stop</button>

<script>
  function start() {
    google.script.run.SuccessHandler(running).startScript();
  }

  function running(e) {
    console.log('Script is running');
  }

  function stop() {
    google.script.run.withSuccessHandler(stopped).stopScript();
  }

  function stopped() {
    console.log('Script has stopped');
  }
</script>

The Server (HTML is served as a web app)

function startScript() {
  do {
    Logger.log('Script running');
    Utilities.sleep(5000);
  } while (keepRunning());
  return 'OK';
}

function keepRunning() {
  var status = PropertiesService.getScriptProperties().getProperty('run') || 'OK';
  return status === 'OK' ? true : false;
}

function stopScript() {
  PropertiesService.getScriptProperties().setProperty('run', 'STOP');
  return 'Kill Signal Issued';
}

function doGet(e) {
  PropertiesService.getScriptProperties().setProperty('run', 'OK');
  return HtmlService.createHtmlOutputFromFile('html').setSandboxMode(HtmlService.SandboxMode.IFRAME);
}


from thetechxp https://ift.tt/ILmXjpJ
via IFTTT

Comments

Popular posts from this blog

किस महानगर में मिल रहा सबसे सस्ता पेट्रोल? जानें तेल का नया भाव https://ift.tt/zKAj5k6

रोज की तरह आज यानि 9 दिसंबर को भी तेल के नए रेट जारी कर दिए गए हैं. जिसके अनुसार, पेट्रोल-डीजल की कीमतों में कोई बदलाव नहीं किया गया है. सभी राज्यों में वाहन ईंधन की कीमतें जस की तस हैं. आइये जानते हैं, किस महानगर में सबसे कम कीमत पर पेट्रोल मिल रहा है और देश के किस इलाके में सबसे सस्ता और सबसे महंगा पेट्रोल मिल रहा है. from आज तक https://ift.tt/o9nAWyY via IFTTT

Best Website For Finding Government Jobs

  Online Sarkari Job Find   is a reliable and comprehensive online platform dedicated to providing the latest information on job opportunities. Our mission is to assist job seekers in finding their ideal positions by offering timely alerts and notifications on the latest job openings, Sarkari Results, Sarkari Exams, Sarkari jobs, Sarkari networks, and Sarkari Naukri. Our team of dedicated professionals is committed to keeping you informed about the most recent developments in the employment sector. With our user-friendly interface and up-to-date content, we strive to ensure that you have access to accurate and reliable information regarding various government job vacancies. Website Link -  Online Sarkari Job Find

IPL: कप्तान बाहर, दिग्गज भी निकले... रिटेंशन ने कैसे बदल दिया टीमों का गणित https://ift.tt/L7Adk8F

आईपीएल के अगले सीजन के लिए 23 दिसंबर को कोच्चि में मिनी ऑक्शन का आयोजन होना है. इस नीलामी से पहले सभी 10 टीमों की ओर से रिटेंशन लिस्ट जारी कर दी गई. from आज तक https://ift.tt/LK4D2kX via IFTTT