Response time API call too large

Hi,

I have developed the Strava app for Homey (Strava App voor Homey | Homey).

Codebase is on Github (GitHub - ThaYoung1/com.thayoung1.strava).

As soon as an item on Strava is created/edited, my App receives an API call (not being an official Homey webhook call) which is handled by the code in my api.js file. So far so good.

Problem is that the POST API method of my App returns a very slow response. Often the response takes about 6 seconds or more. Strava sees that as a failure and will try again and again up untill 3 times. My App does not have to check things before returning a HTTP 200 OK, it could be sent immediately after receiving the call.

I have been experiencing with async handling but can’t get the API method just to accept the call and directly return a HTTP 200 OK.

Can anybody help me to get this thing resolved?

Regards,

ThaYoung1

So what exactly is taking up those 6 seconds?

Hey @robertklep,

Thanks for your reply.

The App does all kinds of things after receiving a request from Strava;

  • it GETs the full Activity details by requesting the Strava API
  • it processes the activity details, calculates new metrics and starts the relevant Homey flow action cards

The thing is, I don’t want the API on my Homey App side, which is called by Strava to be waiting on all these actions; after receiving the request I want it to directly respond with an OK so it won’t be seen as a timeout from Strava’s perspective. I thought that a async method would fix that, but it looks like it is still waiting.

I am thinking about trying to introduce a queueing mechanism in which I just receive the API call from Strava, save it in the queue and subsequently process it in parallel with another process. That will fix it, but I was wondering if there was a ‘quick fix’ so I don’t have to introduce queueing for it.

Regards

You now have this:

    async get({ homey, query }) {
      // you can access query parameters like "/?foo=bar" through `query.foo`
      const result = await homey.app.get(query);
      return result;
    },

This means that the API endpoint will wait for homey.app.get() to complete before it returns the result.

If you just want to send back a generic response, you can remove the await:

    async get({ homey, query }) {
      homey.app.get(query);
      return 'ok'; // or whatever response Strava wants
    },

This will “schedule” homey.app.get() to run, but it will not wait for its completion. So the response of the API endpoint should be fast enough for Strava not to think it’s a failure.

Hi, my GET method needs to wait on response, which is no problem because the code behind it executes fast / does not rely on external systems.

The problem I am describing occurs with the POST method, which already does a function call without await. But that method still gives slow response / seems to be waiting for all further processing before giving an HTTP response to the external system.

  async post({ homey, body }) {
        // access the post body and perform some action on it.
        homey.app.post(body)
        
        return null;
    },

So when you remove the call to homey.app.post(body), it works? Also, have you tried returning anything else besides null?

I will give it a try and report back the results here.