How to create zap delays of less than 1 minute (between 1 - 10 seconds)

  • 25 September 2019
  • 4 replies
  • 7332 views

Userlevel 7
Badge +10

One of the many useful features of Zapier is the "Delay For" step.

However, one of its limitations is that delays must be a minimum of 1 minute.

Screen Shot 2019-09-25 at 13.25.22.pngIn a lot of situations this might be too long, so I got to thinking about a way around this.

Once again, a Javascript Code step can help.

Reading the documentation, one of the limitations is as follows:

Screen Shot 2019-09-25 at 13.28.51.pngCode steps can run for up to 10 seconds before your zap will throw an error. So, what if we just create a Code step that does nothing for 10 seconds, then returns a dummy result?

Well, this does the job:

Screen Shot 2019-09-25 at 13.30.21.png

var now = new Date().getTime();

var millisecondsToWait = 9900; /* i.e. almost 10 seconds */

while ( new Date().getTime() < now + millisecondsToWait )

{

/* do nothing */

}

output = [{id: 123, hello: "world"}];

What this code does is get the current UNIX timestamp in milliseconds, then adds 9900 milliseconds to that timestamp (9.9 seconds).

A loop then constantly gets the current UNIX timestamp in milliseconds, and until it equals the previous number (i.e until another 9900 milliseconds has gone by) it keeps looping.

After that, it returns a dummy "hello = world" value and the zap continues on with the next step.

(PS - trial and error showed that waiting 10,000 milliseconds usually caused an error as it takes Zapier a few milliseconds more to run the complete script - 9900 worked well in testing).

 

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Userlevel 7
Badge +8

@Luhhu I will put in a feature request for this but it's likely due to what @Openside mentioned here.



Userlevel 7
Badge +10

@Openside Thanks - I'm guessing it's a resource-intensive Pandora's Box.

Mind you, it would make sense to give Expert/Team/Company plans a more generous limit - 30 seconds maybe. @jesse / @Danvers - you reckon Zapier HQ would allow it?

And while I think about it, why the 1 min minimum limit anyway? Seems so arbitrary.


Userlevel 5
Badge +3

Nice truck. This brings up a big pet peeve of mine. The code block should be able to run longer than 10 seconds. I got burned by that thinking it could run for 30 seconds like the other actions.


And even 30 seconds is not enough for normal connectors. I wish that could get increased. I tried asking and was told it's not possible :(


Userlevel 5
Badge +3

The one minute minimum on delay is likely due to aws limit in it's message queue delay