简体   繁体   中英

How do I make set a google script trigger to run again if there is an error?

I have a google sheet to keep stack of live stock prices and portfolio valuations. Also, I have some script which runs once a day to provide a permanent record of the valuation. However, sometimes the stock prices do not load immediately, so the permanent record contains errors. What is the best way of fixing this ? For example, can I set a trigger to repeat after 30 minutes if there are errors in certain cells ?
I did try a loop to repeat the process within the script if there was an error, but as the maximum time google script can run for is about 5 minutes, it is not effective.

Example output

One possible solution is to set up a control sheet with two variables:

  • has the script run today? True/False
  • does the sheet have errors? True/False (by using the isError() formula on the portfolio sheet)

Trigger One: trigger a script first thing in the morning to set the "Has the script run today" value to 'False'.

Trigger Two: trigger a second script (say) every hour to check if

  • the main script run today? False >> Run main script || True >> check for errors
  • does the sheet have errors? True >> Run main script || False >> end

You could run Trigger Two more or less frequently depending on how many iterations it takes to get rid of all the errors.

But do remember that there is a quota for the total trigger run time as well: 90 min per day for a consumer account .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM