Random wait time in seconds doesn't seem to be working

Describe the problem/error/question

I have a workflow triggered by a webhook. Because the system that sends the webhook can send tons at the same time and my workflow uses an API with a throttle limit, I added some random seconds to wait after receiving the webhook but before doing the workflow tasks. This is between 0 and 300 seconds (5 min).

Everything is executing, but the random wait time doesn’t seem to be doing anything. Here’s the timeline of an an example execution:

  1. webhook called, execution of workflow starts at 13:01
  2. Random wait time is 193 seconds, a little over 3 minutes
  3. Sub-workflow, which is called by this webhook workflow, starts at 13:01 with it’s own execution id
  4. Database update made by sub-workflow is made at 13:01 according to database

So it seems like the Wait node is not doing anything. I’ve used an Edit Fields/Set node to see the wait time in seconds used by the Wait node during an execution.

What is the error message (if any)?

N/A

Please share your workflow

Set/Edit Fields:
Fields to Set: wait_time_seconds = {{ Math.floor(Math.random() * 300) }}

Wait Node:
Resume: After Time Interval
Wait Amount: {{ $json.wait_time_seconds }}
Wait Unit: Seconds

Share the output returned by the last node

Output of Edit Fields/Set and Wait nodes:
[ { "wait_time_seconds": "v" } ]

Information on your n8n setup

  • n8n version: n8n cloud, 1.81.4
  • Database (default: SQLite): Unknown
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Unknown
  • Operating system: Unknown

The example flow you provided I do not see any random actions taking place. The generate random seconds up to 300 seems to be a set node with no content (at least in the renderer on the forums).

I would recommend using a code node or just an inline expression in the wait node. Easy.

The example flow you provided I do not see any random actions taking place. The generate random seconds up to 300 seems to be a set node with no content (at least in the renderer on the forums).

I notice those nodes where empty and added this to my original post to show the javascript I’m using to generate the random number.

Fields to Set: wait_time_seconds = {{ Math.floor(Math.random() * 300) }}

I don’t know why those nodes were cleared when I downloaded the workflow.

I’ll try it again here.

Ah interesting. That should work. I’d say, unless need elsewhere, make that an inline expression on the wait node rather than pre-set. Or try not force cast it within the set node as a string, that could be the issue. It should be a number.

1 Like

Or try not force cast it within the set node as a string, that could be the issue. It should be a number.

Just had to change the type of the “Fields to Set” from String to Number and it now works correctly.

For clarity, I use the Set/Edit Fields node because I want each execution to save/include the value it waited. If you use this JavaScript directly in the Wait node, then there’s no way to know how long it waited in that particular execution.

Thanks for the help.

1 Like

Ah yeah thats a solid reason. Glad that fixed it!