Google Apps 脚本服务一天使用过多计算机时间 [英] Google Apps Script Service Using Too Much Computer Time for One Day

查看:20
本文介绍了Google Apps 脚本服务一天使用过多计算机时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在昨天运行的 1 (one) 脚本的主题中收到了错误消息,我假设我今天会收到类似的消息.

So I got the error message in the subject on the 1 (one) script I had running yesterday and I am assuming I will get a similar message today.

我改进了脚本(它有一个每分钟运行一次的触发器),因此它的功能更多地符合它的预期,但是错误消息让我思考什么样的功能或程序位可能要求比其他人更多的服务时间.

I have improved the script (which has a trigger to run once per minute) so it functions more along the lines of how it is supposed to however the error message got me thinking as to what sort of functions or bits of programs might be asking for more service time than others.

例如,我不得不在我的 google 应用程序脚本中使用多个睡眠调用来允许数据导入运行并再次运行以处理工作表更改/复制粘贴调用.就使用的服务时间而言,所有这些睡眠呼叫都对我不利吗?

For example, I have had to use multiple sleep calls in my google apps script to allow the data import to run and again for the worksheet changes/copy paste calls to process. Are all those sleep calls counting against me in terms of service time used?

我会代表社区要求将此作为一个开放式问题,而不是特定于睡眠功能.脚本的哪些部分需要服务时间,哪些不需要(如果有).

I would ask on the community's behalf that this be left as an open ended question not specific to the sleep function. What sorts of parts of a script are demanding service time and which are not (if any).

推荐答案

每次调用服务(电子表格、日历或其他)比常规 JavaScript 操作花费更多时间.例如,如果您必须修改电子表格中的 10 个单元格,调用 range.setValue() 10 次比将所有数据放在一个数组中然后使用 range.setValues() 一次性更新电子表格花费的时间要多得多.

Every call to a service (Spreadsheet, Calendar or whatever) takes more time than regular JavaScript operations. For example, if you have to modify 10 cells in a Spreadsheet, calling range.setValue() 10 times takes far more time than having all the data in an array and then updating the spreadsheet in one go using range.setValues().

如果您可以粘贴您的代码片段,社区将能够就如何改进您的脚本提供更多建议.

If you can paste pieces of your code, the community will be able to offer more advice on how to improve your script.

这篇关于Google Apps 脚本服务一天使用过多计算机时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆