Exponential Backoff in Eventing function

Hi, I’m trying to write an eventing function that calls a REST endpoint in an exponential backoff manner. Is there a way to do this please?

The Eventing documentation is here - Eventing Service: Fundamentals | Couchbase Docs

The Eventing Examples documentation is here - Examples: Using the Eventing Service | Couchbase Docs

There is advice on making REST calls here - javascript rest call - Google Search

And retrying with exponential backoff in javascript here - rest call exponential backoff javascript - Google Search

thank you, saw all of them, is there no way to define or use async in the eventing service?

https://www.google.com/search?q=site%3Ahttps%3A%2F%2Fdocs.couchbase.com%2Fserver%2Fcurrent%2Feventing+async

The first link looks promising.

https://docs.couchbase.com › server › current › eventing

Timers are asynchronous compute, which offers Eventing Functions the ability to execute in reference to wall-clock events, refer to the detailed Timers …

Thanks again, looks like I can’t use async functions at top-level. I’ll figure a way around this, but I’m running into a different issue now. I’m making a REST call, but it’s failing. I’m seeing no logs for it though to further understand the issue. How do I log curl requests within the eventing script please?

By the way, setTimeout is not being recognized and throwing a reference error. Is there an alternative way of leveraging this method within the Eventing script?

logging: Language Constructs | Couchbase Docs

So your function will need to capture the message and log it as shown. There is a “Log” link in the UI to display the logged messages. When creating the function, under Settings, there is a System Log Level.

setTimeout is not being recognized

Yes. The sample in the documentation says:

setTimeout(function(){}, 300); // Not allowed - asynchronous flow.

and

Limited asynchrony is added back through time observers (or Timers).

Here is the sample for creating a timer function.

1 Like

Here is a great blog talking about how to create a “dead letter queue” … I would not always spin up timers for the cURL… I would try the curl 2-3 time 10 seconds apart and if it fails spin up a CouchBase Eventing Timer to retry the cURL ever XYZ minutes.

Sorry for the delay in responding here - swamped with work.

I managed to get this done via timers themselves managed via traditional looping constructs :slight_smile:

Sadly the JS runtime in Eventing is very restricted and isn’t allowing some async constructs.

Marked @mreiche 's describing timers as asynchronous compute actually triggered me to think of them as a potential solution

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.