これはまったく間違った方法で近づいています。スクリプト内でトリガを使用して実行を再開する可能性を含める必要があります。私はどのようにそれをやったかをお見せします。私のスクリプトはかなり大きく、ループを実行するので、ループ内のどこで停止したのかを覚えておかなければならないので、同じデータを続けることができます。
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Purpose: Check if there is enough time left for another data output run
// Input: Start time of script execution
// Output: Boolean value if time is up
function isTimeUp(start, need) {
var cutoff = 500000 // in miliseconds (5 minutes)
var now = new Date();
return cutoff - (now.getTime() - start.getTime()) < need;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ここstart
は、単にあなたがスクリプトを起動するときに作成するnew Date()
です。 need
は、スクリプトが1ループを実行するのにかかる平均時間です。ループに十分な時間がない場合は、別の関数でスクリプトを終了します。
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Purpose: Store current properties and create a trigger to start the script after 1 min
// Input: propertyCarrier object (current script execution properties)
// Output: Created trigger ID
function autoTrigger(passProperties, sysKeys) {
var sysProperties = new systemProperties();
if (typeof sysKeys === 'undefined' || sysKeys === null) {
sysKeys = new systemKeys();
}
var triggerID = ScriptApp.newTrigger('stateRebuild')
.timeBased()
.after(60000)
.create()
.getUniqueId();
Logger.log('~~~ RESTART TRIGGER CREATED ~~~');
//--------------------------------------------------------------------------
// In order to properly retrieve the time later, it is stored in milliseconds
passProperties.timeframe.start = passProperties.timeframe.start.getTime();
passProperties.timeframe.end = passProperties.timeframe.end.getTime();
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Properties are stored in User Properties using JSON
PropertiesService.getUserProperties()
.setProperty(sysKeys.startup.rebuildCache, JSON.stringify(passProperties));
//--------------------------------------------------------------------------
Logger.log('~~~ CURRENT PROPERTIES STORED ~~~');
return triggerID;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
あなたは(あなたが最初から開始するかどうか気にしない、あなたの現在の実装で判断)停止した場所を覚えておく必要がない場合ユアーズは、より単純化することができます。
作成するトリガーは、メイン関数のいずれかを使用するか、データを渡す必要がある場合は、ユーザープロパティからデータを取得して渡すために、別のスターター関数が必要です。
greasemonkeyではなく、時間駆動のトリガーを使用します。 https://developers.google.com/apps-script/guides/triggers/installable#time-driven_triggers –
またはタイムアウトエラーをキャッチしてスクリプトを再度呼び出すhtmlを参照してください。 –
私は研究の努力がゼロであるので、この質問をdownvotingしています。コンソールのスクリーンショットを作成しました。期待どおりに動作しないコードはどこにありますか?また読む:http://stackoverflow.com/help/how-to-ask –