![](/img/trans.png)
[英]How to stop a google app script from an infinite loop always executed when opening the Google Spreadsheet document?
[英]How to stop or limit Google spreadsheet app script from running parallelly?
我有一個如下所示的電子表格。
一種 | 乙 | |
---|---|---|
0 | RJ162718 | =FetchScript(A0) |
1個 | RJ258445 | =FetchScript(A1) |
2個 | RJ228027 | =FetchScript(A2) |
3個 | RJ258362 | =FetchScript(A3) |
... | ... | =FetchScript(...) |
FetchScript function 使用UrlFetchApp.fetch(url)
來獲取不允許大量 api 調用的網站。
如何停止腳本並行運行或限制一次執行的次數?
謝謝。
編輯:
A列是UrlFetchApp.fetch(url)
中url的一部分,例如:
functtion FetchScript(ColunmA) {
url = "https://example.com/" + ColumnA;
response = UrlFetchApp.fetch(url);
//do something
}
雖然我不確定你的 FetchScript FetchScript
的細節,但是當我看到你展示的示例表時,我猜你的FetchScript
可能如下所示。
function FetchScript(value) {
// do something.
var res = UrlFetchApp.fetch(url);
// do something.
return output;
}
在這種情況下,當=FetchScript(A1)
, =FetchScript(A2)
,,, 被放置時,每個 function 都與異步進程一起運行。 如果想用同步進程運行function,下面的修改怎么樣?
function FetchScript(values) {
var results = values.map(e => {
// do something.
var url = "###";
var res = UrlFetchApp.fetch(url);
// do something.
return output; // In this case, please return 1 dimensional array for putting values to the row direction.
});
return results;
}
在這種情況下,請將自定義 function 像=FetchScript(A1:A10)
放到單元格中。 這樣,單元格值將用於此修改后的 function。
在此修改中, UrlFetchApp.fetch
與同步進程一起運行。
如果你想在特定的數字中運行UrlFetchApp.fetch
,你也可以使用下面的腳本。
function FetchScript(values) { var limit = 5; // Please set the number of run of UrlFetchApp.fetch. In this case, 5 values are used. var results = values.splice(0, limit).map(e => { // do something. var url = "###"; var res = UrlFetchApp.fetch(url); // do something. return output; // In this case, please return a 1-dimensional array for putting values to the row direction. }); return results; }
// do something
實現目標的方法。 因此,當您測試此方法時,請在您的實際腳本中反映這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.