Excel Power Query - Sleep or Wait Command to Wait on API Rate Limit

北城以北 提交于 2021-02-04 19:58:51

问题


In Excel Power Query (PQ) 2016, is there such a function that can insert a "SLEEP 15 seconds" before proceeding? Not a pause, but a sleep function.

Problem: I wrote a function in PQ to query: https://westus.api.cognitive.microsoft.com/text/analytics/v2.0. That function works fine, as designed.

I have a worksheet with 10K tweets that I want to pass to that function. When I do, it gets to ~60 or so complete and I get an ERROR line in PQ. A look at Fiddler says this:

message=Rate limit is exceeded. Try again in 11 seconds. statusCode=429

I think if I insert a SLEEP 5 second (equivalent) command into the PQ function, it won't do this.

Help & thanks.


回答1:


You want Function.InvokeAfter

 Function.InvokeAfter(function as function, delay as duration) as any

Here's an example:

= Function.InvokeAfter( () => 2 + 2, #duration(0,0,0,5))

Returns 4 after waiting 5 seconds.


To answer a question you didn't ask yet, if you're going to execute the exact same Web.Contents call a second time, you may need to use the

[IsRetry = true]

option of Web.Contents to indicate you actually want to run the web request again..



来源:https://stackoverflow.com/questions/40411616/excel-power-query-sleep-or-wait-command-to-wait-on-api-rate-limit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!