为什么我的Apps脚本突然停止工作?

编程入门 行业动态 更新时间:2024-10-26 23:29:24
本文介绍了为什么我的Apps脚本突然停止工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

几个月来,我在Google表格中使用了以下Apps脚本代码,都没有问题.

I have used the following Apps Script code, inside a Google Sheet, for several months without problem.

由每天晚上9点至晚上10点的时间触发触发,它会从我的Google日历中获取同一天的每个事件,并将包含这些详细信息的相应行添加到Google表格中.

Fired by a time time trigger at 9pm-10pm daily, it fetches each event from same day from my Google Calendar and adds a corresponding row with those details to a Google Sheet.

// Add Google Calendar events to Google Sheets. // Sheet row additions to fire Zapier ClickTime actions. // Script originally from blog.ouseful.info/2010/03/05/grabbing-google-calendar-event-details-into-a-spreadsheet/ function caltest3(){ //www.google/google-d-s/scripts/class_calendar.html#getEvents // The code below will retrieve events between 2 dates for the user's default calendar and // display the events the current spreadsheet var cal = CalendarApp.getDefaultCalendar(); var sheet = SpreadsheetApp.getActiveSheet(); // Today's date, via stackoverflow/questions/46548281/how-to-reference-todays-date-in-javascript var today = new Date(); var dd = today.getDate(); var mm = today.getMonth(); var yyyy = today.getFullYear(); // Use Google Calendar classes, developers.google/apps-script/reference/spreadsheet/sheet#appendRow(Object): // Get all events between this range var events = cal.getEvents(new Date(yyyy, mm, dd, 0, 0, 0), new Date(yyyy, mm, dd, 23, 0, 0)); // For every event, for (var i=0;i<events.length;i++) { // Calculate hour length of event var hours = Math.abs(events[i].getEndTime() - events[i].getStartTime()) / 36e5; // Combine elements of event // var details=[[events[i].getStartTime(), events[i].getEndTime(), hours, events[i].getTitle(), events[i].getDescription()]]; // Appends a new row with columns to the bottom of the spreadsheet containing the values in the array sheet.appendRow([events[i].getStartTime(), events[i].getEndTime(), hours, events[i].getTitle(), events[i].getDescription()]); } }

但是,一夜之间,我收到了Google的这条消息...

But, overnight, I received this message from Google...

您的脚本日历传输"最近未能完成成功地.故障摘要如下所示.配置此脚本的触发器,或更改您的接收设置将来的失败通知,请单击此处.

Your script, Calendar Transfer, has recently failed to finish successfully. A summary of the failure(s) is shown below. To configure the triggers for this script, or change your setting for receiving future failure notifications, click here.

该脚本由文档日历清单"使用.

The script is used by the document Calendar Listings.

此致Google Apps脚本

Sincerely, Google Apps Script

行最后一次成功添加是在2月15日.没有任何事件要添加到2月16日或17日,因此2月18日是第一个失败.

The rows were last successfully added on Feb 15. There were no events present to add on Feb 16 or 17, so Feb 18 is the first failure.

这是怎么回事?

与从经典日历到新日历的切换有关吗?

Is it anything related to the switch from Classic Calendar to New Calendar?

或者在添加到表格时似乎遇到了麻烦?

Or looks like it is having some trouble adding to Sheets?

第34行是标记为追加新行... 的最后一行.

Line 34 is the final row marked Appends a new row ....

推荐答案

我在此网站上搜索并在Google中搜索了服务超时".错误.看来此错误意味着Google服务器的响应速度不够快.

I searched on this site and googled for "service timed out" error. It looks that this error means that Google servers didn't responded fast enough.

注意:Google服务器的响应时间不确定.有时它们比其他的更快,并且希望它们很少如此慢,以至于服务超时".错误发生.

NOTE: Google servers response time isn't deterministic. Sometimes they are faster than others and hopefully very rarely the are so slow that the "service timed out" error occurs.

一种解决方案是使用Bruce McPherson的指数补偿库或类似的东西.

One solution is to use the exponential backoff library from Bruce McPherson or something similar.

什么是指数补偿

这是推荐的技术,用于速率受限的呼叫服务.如果检测到它们失败,并通过使用特殊的等待算法可以恢复的错误而失败,它们将被重试几次.与每次调用之间使用Utilities.sleep相比,这是一种更好的技术,因为它仅在需要时才等待,因此不会浪费任何执行时间.

This is recommended technique to use for calling services that are rate limited. They will be retried a few times if they are detected as having failed with errors that can be recovered from using a special wait algorithm. This is a much better technique than using Utilities.sleep between each call since it only waits if it needs to and therefore doesn't waste any execution time.

另一种方法是创建一个脚本变体,以在时间驱动的触发脚本失败时运行.

Another approach is to create a script variant to be ran when the time-driven triggered script fails.

参考文献:

  • Google App脚本优化
  • 执行失败:服务超时

更多推荐

为什么我的Apps脚本突然停止工作?

本文发布于:2023-06-06 04:44:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/534747.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   工作   Apps

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!