-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Events removed when URL returns 5xx #343
Comments
Sounds like this may be solved by #235 - however, this has become stale. |
Don't think this has been fixed. I had a http 500 error when pulling a .ics file from google drive, and the script seems to think it pulled 0 events and proceeded to delete all the events on my google calendar. Is there a way to handle the error so that when you get a http 5xx error, the script just stops and hopefully the next run will refresh the ics? |
I just ran across this same issue last week. I have an ical that is returning "[ERROR] Incorrect ics/ical URL..." and then all of the events are deleted. I looked at #235 , but I hesitated to implement that code you gave Jonas because it looks like there are some conflicts with newer code in the script (colorID, etc.). I also didn't really see where it was so different than what was in the Master in terms of handling the error (but you know my coding prowess is weak-sauce). |
Here's my easy and simple to understand fix: Line 147 in e5cd8e0
So, on this line it fetches your ics file and reads the number of calendars. Line 161 in e5cd8e0
In theory, if the script fails to fetch the calendars, it will return 0 calendars and there will be nothing to sync. So, what I did is I added a length == 0 check and tell the script to continue to the next url, skipping the rest of the import or delete code. The code will look like this:
the term Line 147 in e5cd8e0
|
Meanwhile this is my quick and easy fix until the owners of this project releases a new version. I scheduled it to sync every 6 hours so there's always a next retry and it won't put so much load on my server. If every request returns 500, then it might be something to do with the source url. |
Stop on nil response to mitigate 5xx errors discussed at derekantrican#343
I encountered the same problem. Due to spurious service I see something like this:
The entire calendar is deleted! Then 10 minutes later on the next run:
...the calendar is suddenly restored. Two suggestions:
|
@octogonz Have you tried my solution had worked if 403 is encountered? |
Not sure which solution fixed missing Outlook calendar events in my Google calendar since I copied over both: this and #386 — not matter which, I'd like to thank both contributors! Thank you! |
@jerrywoo96 if I understand correctly, your fix essentially ignores network failures, temporarily skipping the sync for that calendar. In my case, the calendar contains important events that are used to manage my week. Comparing...
...then the first one actually seems safer. At least I will immediately notice that something is broken. The second approach could lead to embarrassment of scheduling conflicting meetings or not showing up for events, until I finally realize that the calendar is outdated. This is why I was asking about a notification mechanism: When the syncing fails, the script should send an email alert, or maybe insert a fake "error" event on the calendar, etc. |
I have no idea if it works or not. Update the thread if it works. Line 1039 in 71bb0a6
|
Suppose we wanted to send at most one notification email per day? Does the Google Apps Script have any way to remember state between runs? Software engineering is hard. 😄 |
From a little research, it seems like we should be able to do something like: var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty('lastEmailSent', new Date().toISOString()) I'll try this when I get some time. |
I'm now experiencing this error very frequently. It is probably not Google Calendar's fault, but rather decreased reliability of the company that provides my calendar service. Looking more closely at the code, the script implements a retry/backoff for each network request: var defaultMaxRetries = 10; // Maximum number of retries for api functions (with exponential backoff) /**
* Runs the specified function with exponential backoff and returns the result.
* Will return null if the function did not succeed afterall.
*
* @param {function} func - The function that should be executed
* @param {Number} maxRetries - How many times the function should try if it fails
* @return {?Calendar.Event} The Calendar.Event that was added in the calendar, null if func did not complete successfully
*/
var backoffRecoverableErrors = [
"service invoked too many times in a short time",
"rate limit exceeded",
"internal error"];
function callWithBackoff(func, maxRetries) {
var tries = 0;
var result;
while ( tries <= maxRetries ) {
tries++;
try{
result = func();
return result;
}
catch(err){
err = err.message || err;
if ( err.includes("HTTP error") ) {
Logger.log(err);
return null;
} else if ( err.includes("is not a function") || !backoffRecoverableErrors.some(function(e){
return err.toLowerCase().includes(e);
}) ) {
throw err;
} else if ( tries > maxRetries) {
Logger.log(`Error, giving up after trying ${maxRetries} times [${err}]`);
return null;
} else {
Logger.log( "Error, Retrying... [" + err +"]");
Utilities.sleep (Math.pow(2,tries)*100) +
(Math.round(Math.random() * 100));
}
}
}
return null;
} There are 10 reattempts at exponential intervals (200ms, 400ms, 800ms...) producing an overall delay (200ms, 200+400=600ms, 200+400+800=1400ms, ...) which I calculated should delay about ~3.5 minutes for all 10 failures. This should be pretty robust. HOWEVER, this retry logic is ONLY applied for recognized error messages ( Maybe
I'll experiment with this idea and follow up. |
I also noticed that Lines 162 to 164 in 17cde1a
However in the snippet above, the Lines 1098 to 1103 in 17cde1a
Apparently this inconsistency was introduced by @jonas0b1011001 in #245 which was trying to improve error handling with multiple calendars: If the first calendar reports an error, processing should continue for the other calendars. But it seems like a mistake to completely disable retries for all HTTP operations. 🤔 |
Update: Enabling retries for the HTTP requests definitely seems to resolve the intermittent connection failures that I had encountered. 👍 I also found that if important an error occurs (the total failure to sync a calendar after retries), the script can throw an uncaught top-level exception which will cause the run to appear as "failed" in the "Executions" log. This makes it easier to identify how frequently such failures are occurring. I'm going to try this solution for a while. If it performs well, then I'll contribute a PR with these changes. |
Here's my PR: #403 |
The problem
When the URL returns HTTP Error 5xx, Events are removed from the calendar.
Is it possible to do nothing to the calendar if requests are not successful?
Version of GAS-ICS-Sync
5.7
Additional information & file uploads
var howFrequent = 360;
var onlyFutureEvents = false;
var addEventsToCalendar = true;
var modifyExistingEvents = true;
var removeEventsFromCalendar = true;
var addAlerts = "no";
var addOrganizerToTitle = false;
var descriptionAsTitles = false;
var addCalToTitle = false;
var addAttendees = false;
var defaultAllDayReminder = -1;
var overrideVisibility = "public";
var addTasks = false;
var emailSummary = true;
The text was updated successfully, but these errors were encountered: