I have used the Google API Ruby client example repo on Github as a starting point for my calendar app.
It works well and usually without issues. Lately, however, I noticed that my app in production does not fetch all events. I present events in a table after a few calendars have been requested through the ruby client. On my initial call there are just the dates which I generate with my app, no data is fetched from the calendars at all. Upon second request some calendars will return data and reloading the app a couple more times all calendars will return events.
So to me it seems like there is some caching going on. If data is not returned quick enough an empty response is sent back to me. Requesting again sends some data and the more I request the more data is returned.
Maybe there is something wrong with my setup which is not perfect I assume:
get '/' do
#fetch all calendars
result = api_client.execute(:api_method => calendar_api.calendar_list.list,
:authorization => user_credentials)
cals = result.data.items.map do |i|
#skip id calendar does not belong to owner or is the "private" primary one
next if i.primary || i.accessRole != "owner"
i.summary
end
cals.compact!
#save all users mentioned in calendars in a set
events_list = result.data.items.map do |i|
#skip calendar if primary or not owned by user (cannot be changed anyway)
next if i.primary || i.accessRole != "owner"
r = api_client.execute(:api_method => calendar_api.events.list,
:parameters => {'calendarId' => i.id},
:timeMax => DateTime.now.next_month,
:timeMin => DateTime.now.beginning_of_month)
#capture all calendars and their events and map it to an Array
r.data.items.delete_if { |item| item.status == "cancelled" }
end
#remove skipped entries (=nil)
events_list.compact!
slim :home, :locals => { :title => Konfig::TITLE, :events_list => events_list, :cals => cals}
end
BTW: :timeMax and :timeMin are not working as expected either but that's a different question I suppose.
Code does not seem to be the issue here.
I would guess one of the following is happening
What would I do in this situation. I would the following before deciding on next steps
Print the response object error codes and http headers in the api client gem from its response object. I would be looking for what is the caching header in response and what is the status code.
If you have ngrep on your production machine, just let it print and show the entire http request response instead of printing it in the gem.
If the response takes more than 2 seconds, increase timeout settings for net::http and check.