Running parallel tasks as a web app

Up till now we've been dealing with running this stuff as a sidebar on  spreadsheet.

Now we'll take the example in Parallel implementation and getting started - doing some cryptography exercises in parallel and run it as a web app.  You could add a bunch of parameters to this - even passing an entire profile as a parameter, but for simplicity we'll just set up a default profile and use that. 

I'm going to use  the same script as I used in Parallel implementation and getting started, but add a doGet() function to handle the webapp functionality, and publish it. It's just a few lines.

function doGet(e) {

  return worker (cryptoProfile(25,false));    
  
}

function worker (profile) {

  
  var htmlName = 'asyncService';
  
  var html = HtmlService.createTemplateFromFile(htmlName)
               .evaluate()
               .getContent();

  html += "<script>\n" + 
        "doSomeThings( " +
          JSON.stringify(profile) +
        ");\n</script>";
 
  return  HtmlService.createTemplate(html).evaluate()
    .setSandboxMode(HtmlService.SandboxMode.NATIVE);
}

As you've been reading this, I've been running a bunch of parallel cryptographic tasks in the Apps Script cloud. See below for progress. You'll see that we got through about 1 minutes worth of work in about 20 seconds.



  

For more on this topic, see Running things in parallel using HTML service. For more snippets like this see Google Apps Scripts snippets
For help and more information join our forum,follow the blog or follow me on twitter .

You want to learn Google Apps Script?

Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, available All formats are available now from O'Reilly,Amazon and all good bookshops. You can also read a preview on O'Reilly

If you prefer Video style learning I also have two courses available. also published by O'Reilly.
Google Apps Script for Developers and Google Apps Script for Beginners.






Comments