Successful but execution time limit exceeded

I’m trying out a trigger which adds an object to algolia upon inserting to mongodb. In my case the object gets added to algolia successfully but the function doesn’t seem to stop and runs until timeout

My function

exports = function(changeEvent) {
  
  const algoliasearch = require('algoliasearch');
  const client = algoliasearch(context.values.get('algolia_app'),context.values.get('algolia_key'));

  const index = client.initIndex("movies");


  changeEvent.fullDocument.objectID = changeEvent.fullDocument._id;
  delete changeEvent.fullDocument._id;
  index.saveObject(changeEvent.fullDocument)
  .then(({objectID}) => {
    console.log('successfully updated: ',objectID);
  })
  .catch(err => {
    console.log(err);
  });
};

Log

Logs:
[
  "successfully inserted:  61cf0a79c577393620dd8c80"
]
Error:
execution time limit exceeded

I’m I doing anything wrong

Hello @schach_schach

My name is Josman and I am happy to help you with your question. First of all, welcome to our MongoDB Community Forum!

Realm Functions have certain constraints that must be taken into account when using them. One of those is the 120 second execution time.

I will suggest to add a return statement just before your console.log, as follows:

  return index.saveObject(changeEvent.fullDocument)
  .then(({objectID}) => {
    console.log('successfully updated: ',objectID);
    return true;
  })
  .catch(err => {
    console.error(err);
    return false;
  });

Could you try the above?

Looking forward to your response.

Please let me know if you have any additional questions or concerns regarding the details above.

Kind Regards,
Josman

1 Like

Hello Josman,
Thank you for the quick reply!

I tried with the return statements as well. but still it seems to exceed the time limit. The function performs what I want but doesn’t seem to stop :thinking:

I also console logged along with the timestamp and according to it the the console.log runs almost just after the trigger initiating. I’m wondering if it is an issue with the npm package :thinking:

Hello @schach_schach,

I also console logged along with the timestamp and according to it, the console.log runs almost just after the trigger initiating. I’m wondering if it is an issue with the npm package :thinking:

Yes, it could be related to the npm package. Could you please share with me the package.json? I would want to reproduce it locally to see what I could find.

Please let me know if you have any additional questions or concerns regarding the details above.

Kind Regards,
Josman

1 Like

Hello @Josman_Perez_Exposit
since I’m running this in the cloud itself I’m not sure how I can get the package.json
but I’m using algoliasearch v4.11.0

ignore the axios.

Hello @schach_schach

since I’m running this in the cloud itself I’m not sure how I can get the package.json

You can access your npm package by either using the Realm CLI and realm-cli pull with the --include-dependencies. However, the screenshot is sufficient.

I will test it and will let you know.

Kind Regards,
Josman

1 Like

I had to go for EventBridge instead of a Realm function. Still no idea what went wrong with the function.

I have the same issue here, with Algolia too. But in my case the object is not even saved on Algolia, it’s just times out?

Do you know what is the case and how to solve?

I’d like not to resort to EventBridge.

Hello @schach_schach I’d like to acknowledge that the issue was solved, see here:

Of course, test your case. But in my case it is fixed, and am already running in a production app.

1 Like