Home > Software engineering >  Google Calendar Batch Request exceptions
Google Calendar Batch Request exceptions

Time:12-19

I am trying to use Batch Requests with the Google Calendar API for .NET. What I am finding is that if there is any problem with an event in the batch it raises an exception and the whole batch fails with no easy way to check which event has the problem.

For example using their code

UserCredential credential;
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        new[] { CalendarService.Scope.Calendar },
        "user", CancellationToken.None, new FileDataStore("Calendar.Sample.Store"));
}

// Create the service.
var service = new CalendarService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "Google Calendar API Sample",
    });

// Create a batch request.
var request = new BatchRequest(service);

var eventId = "***Bad event id***";

request.Queue<Event>(service.Events.Update(
     new Event
     {
         Summary = "Learn how to execute a batch request",
         Start = new EventDateTime() { DateTime = new DateTime(2014, 1, 1, 10, 0, 0) },
         End = new EventDateTime() { DateTime = new DateTime(2014, 1, 1, 12, 0, 0) }
     }, calendar.Id, eventId),
     (content, error, i, message) =>
     {
         // This is never called!!!
     });

await request.ExecuteAsync();

Using this example to update an event, if I enter a bad event id in the update, it will raise an exception and the whole batch will fail. This would be less bad if the callback would be called and let me know which one, but that doesn't seem to ever even be called

CodePudding user response:

What I am finding is that if there is any problem with an event in the batch it raises an exception and the whole batch fails with no easy way to check which event has the problem.

Yes this is true.

The only solution is to check if the request fails you will need to do an event list to find out which events were created and which were not. Then resend the ones that failed. In my experience most often they all fail and none are created but its not something that you can rely upon, so you need to check.

You will also find that when using batching that you may hit the user flood protection quota issues as all the requests get dumped at the server at the same time increasing your chance for a flooding error. You will then be left with trying to figure out which one failed and which one passed.

The only thing batching saves you is the HTTP Calls. Nothing else.

Batching introduces more issues then its worth, IMO.

  • Related