GASWorker
GASWorker is a library for the script that requires a long run in the Google Apps Script.
Read this in other languages: English, 日本語.
Description
Google Apps Script have a maximum script runtime of 6 minutes of the limitations.
You can use GASWorker a practical feature when you want to run the script over a long period of time beyond this limit.
GASWorker achieves the execution of the script over a long period of time to ** pseudo ** by call to fit within the time limit of a long process that has been divided time-based trigger.
User of GASWorker have to divide the processing of script to run for a long time is done. GASWorker calls the divided processing by using the time-based trigger.
Usage
Initialize
var gwConfig = callbackTarget: this { var cell = userContextsheet; cell; SpreadsheetApp; Utilities; token++; return token < 30 ? token : null; } { return PropertiesService; } { return LockService; }; GASWorker;
- First, you must call
GASWorker.setup()
function in order to initialize. And, you must set argument of 'GASWorker.setup()' function as configuration object. See Define configuration object details of configuration object. getLock
function have to provides Lock object to GASWroker from App Script.getProperties
function have to provides Properites object to GASWroker from App Script.
Define configuration object
In configuration object, define used callback functions and values by GASWorker
.
Define doTask function
{ Logger; Utilities; token++; return token < 30 ? token : null;}
You can define the processes that have been divided into doTask
.
doTask
will be called from time-based trigger.
Return value of doTask
that will be the token
argument of when thedoTask
the next call.
If you return the null
,doTask
is no longer called, processing is terminated.
Argument of doTask
function are initially passed GASWorker.execute ()
argument.
userContext
is object where you can use add, modify and delete any value.
Life of userContext is same to Google Apps Script process.
Note : Process in doTask
must be make to be completed within 6 minutes.
Define beforeTasks function
{ Logger;}
It is optional that to define beforeTasks
function.
You can hook before start tasks using beforeTasks
function.
Define afterTasks function
{ Logger;}
It is optional that to define afterTasks
function.
You can hook before end tasks using afterTasks
function.
Define done function
{ Logger;}
done
is called when processing started is completed GASWorker.execute
.
done
function is optional.
Start Task
{ Logger;}
If you call the GASWorker.execute
function to install a time-based trigger.
doTask
function is called from the installed trigger.
Cancel
{ GASWorker;}
If you want to cancel the process that are started in GASWorker.execute
, call the GASWorker.cancel
function.
Install
NPM
$ npm install gas-worker --save
I recommend to use it with Browserify and gasify.
Library on Apps Script
You can use it as a Library.
- Project Key : MgArHDn4Cqyu5Dem4eLAklPFqzDO4jqHr