Take a moment to read these if this is a new topic for you.
Code is on github GasThreader structureGasthreader is a published Apps Script webapp. I considered making it a library but decided that the best approach was for you to take the template and modify it for your own app. There are a heap of script files in the project, but luckily, there are only 2 or 3 you have to modify, and these all run Server Side.
For re-usability and ease of testing I recommend you make separate Job and Orchestrate work spaces, and keep the specifics of what your app is doing separately - just like this pattern. NotesBear these tips in mind when creating your app
NamespacesI always recommend using namespaces to separate logic, encourage reusability between projects and for general cleanliness. This is the namespace pattern I recommend. var yourNamespace = (function (ns) { // always have an init to ensure you can control execution order for dependencies ns.init = function (args) { // .. do some stuff }; // encapsulate namespace settings in the namespace ns.settings = { yourParam1:100, yourParam2:200 }; // namespace methods look like this ns.yourMethod = function (args) { return something; }; // dont forget this at the end of the ns. return ns; }) ({}); In your work package, which I'll get to next, you would define the execution of something from your namespace like this. instances: { nameSpace:"yourNamespace", method:"yourMethod", arg:args } Executing global functionsAlthough I don't recommend it, there may be times that you want to schedule running a function in the global space. function yourGlobalFunction (args) { return something } This can be specified like this in the work package instances: { nameSpace:"", method:" yourGlobalFunction ", arg:args }
Changing the Orchestration namespace nameBy default this namespace is expected to be Orchestration. You can change it in the Store namespace to something else if you really want to. // work info - need this to get started ns.orchestrationNamespace = "Orchestration"; Next
|
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Orchestration of Apps Scripts - parallel threads and defeating quotas >