Fastest way check adding new task

Hey everyone. I need check new tasks that adding in section. Working with Java and official client.
With checking events - delay between showing in browser and showing in my program- about 5s.
With checking tasks - 0.5s-1s:

           List<Task> result = client.tasks.getTasksForSection("1164252359")
                .option("pretty", true)
                .execute();
        while (found){
            Long temp = System.currentTimeMillis();
            List<Task> result2 = client.tasks.getTasksForSection("1164252359")
                    .option("pretty", true)
                    .execute();
          if (result2.size()>result.size()){
              System.out.println("ADDED task");
              found = false;
          }
            System.out.println(System.currentTimeMillis()-temp);
            try
            {
                Thread.sleep(100);
            }
            catch(InterruptedException ex)
            {
                Thread.currentThread().interrupt();
            }
        }

Maybe API can do it faster with another way? (I’m using paid plan, so by docs 1500 call in minute can be possible)

Yeah, that’s not going to be optimally efficient because you’re re-reading all of the tasks in the section every time. It would be better to use the Events API - that will only get you the changes since the last time you called it, rather than reading all tasks over and over.

1 Like

Thank, you are right theoretically. But 5s Events vs 0.5 second not efficient way, so for my needs events not suitable

I didn’t get into this in my initial answer (was hoping I wouldn’t need to :grin:) but it’s not clear what you mean by “5s Events” and by “checking tasks - 0.5s-1s”. Can you provide more details as to exactly what you’re measuring in each of those cases? In your code and accompanying text, there’s no indication that you’ve used the Events API yet, so I’m not sure where “5s Events” is coming from.

I will make one overall comment: if you’re looking for a case where you can use the API and get the same response times as in the Asana web app, that’s not going to be possible (and I’m not sure there’s any API that can make that type of claim).

2 Likes

Ohh, thanks for detail answer, I thout that API write for faster way do something for services, but I’m new in programming for Web and you broke my dreams :slight_smile:
For events I checked by this code:

for (Event e : client.events.get("1200277534")) {
                System.out.println(e.action + ": " + e.type);
                
  }

After I open 2 different browser, record screen. Make changes in 1 browser than by video recording checked when browser show new info and when my program. In video editing software checking time.

Oh no, so sorry, I hate to be a breaker of dreams! :laughing: