Facing problem while using Event API


#1

Hi All,

I am using event api with java platform and capturing all event for a project. But after 10 -20 minutes later it always shows me error

Exception in thread “Thread-7” java.util.NoSuchElementException
at com.asana.iterator.PageIterator.next(PageIterator.java:54)
at com.asana.iterator.EventsPageIterator.next(EventsPageIterator.java:42)
at com.asana.iterator.ItemIterator.next(ItemIterator.java:25)

or sometime it shows

Exception in thread “Thread-11” com.google.gson.JsonIOException: java.net.SocketTimeoutException: Read timed out
at com.google.gson.Gson.assertFullConsumption(Gson.java:788)
at com.google.gson.Gson.fromJson(Gson.java:776)
at com.asana.requests.ItemRequest.executeRaw(ItemRequest.java:39)
at com.asana.requests.ItemRequest.execute(ItemRequest.java:27)

here is my code:

EventsRequest<Event> request = client.events.get(projectId);
for (Iterator<Event> iterator = request.iterator(); iterator.hasNext();) {
    Event e = (Event) iterator.next();
    String action = e.action;
    String type   = e.type;
}

Can anyone tell me the solution?


#2

Hey there @Kuldeep_Poonia,

The second error is simply a timeout error - trying to read the response, but the request took too long. I believe we’re supposed to retry in this case, but it doesn’t appear that we do. I’ll file an enhancement request in Asana.

I’'m not sure about the first error - calling next() will throw NoSuchElementException if there isn’t another element, but it should be checking with every loop. One brute force method might be to simply break out of the loop as if hasNext() were false in this case, but without being able to sit down and reproduce/debug, I think this will be tricky to track down. Is your app multi-threaded? Is it possible that there’s a race condition where you’re calling next() in a separate thread (or otherwise consuming the event from Asana with a different event stream) that might set up a race condition where hasNext() is true, but the event is consumed somewhere else becore next() is called? :thinking: