Wait node in workflow [GOT CREATED]

Hi @jan,

Is there a way can wait between each item execution in the node?
For example, there is a rate limit in the web server, it will block if we send a lot of HTTP Requests in a short time.

Welcome to the community @Ho_Tommy!

If you want a wait between you would have to add a temporary wait node like above.
There is currently not rate-limiting. If you would need that, it would be best to add something like Kong (Rate Limiting plugin | Kong Docs) in front of n8n.

Hi @jan, sorry for my poor English.

Below is my example code (code and the URL “https://postman-echo.com/get” example are from your website).

I would like to add wait or sleep between the item execution in last node “Send Requests”.
In this example, the last node will be finished to send all 10 requests within 10 seconds.
But in my situation, our web server have rate limit, let say 5 requests per minute.
So I cannot make all requests successful in last node “Send Requests”.

{
  "name": "",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://jsonplaceholder.typicode.com/posts?userId=1",
        "options": {},
        "headerParametersUi": {
          "parameter": []
        }
      },
      "name": "Get Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        420,
        300
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "functionCode": "const newItems = [];\nfor (const item of items[0].json) {\n  newItems.push({json: item});\n}\nreturn newItems;"
      },
      "name": "Split up",
      "type": "n8n-nodes-base.function",
      "position": [
        620,
        300
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "url": "https://postman-echo.com/get",
        "responseFormat": "string",
        "options": {},
        "queryParametersUi": {
          "parameter": [
            {
              "name": "title",
              "value": "={{$node[\"Split up\"].data[\"id\"]  + \" : \" + Date()}}"
            }
          ]
        }
      },
      "name": "Send Requests",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        940,
        300
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "functionCode": "const waitTimeSeconds = 3;\n\nreturn new Promise((resolve) => {\n  setTimeout(() => {\n    resolve(items);\n  }, waitTimeSeconds * 1000);\n});\n\n"
      },
      "name": "Wait",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        780,
        300
      ]
    }
  ],
  "connections": {
    "Get Data": {
      "main": [
        [
          {
            "node": "Split up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split up": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start": {
      "main": [
        [
          {
            "node": "Get Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Send Requests",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {}
}

In this case it is the easiest if you split it in separate batches.

So it would then look like this:

Thanks @jan, it is the easiest and perfect solution!

1 Like

Will this function wait for 1000 seconds?

Can I simply replace Seconds with minutes and hours for more waiting? Will it have any impact?

I have created a function node using this, but getting an error. Do I need to add anything?

It will work theoretically for as long as you want. You just have to be aware of all what I wrote aboveand why long wait times are a bad idea. Because for example if n8n closes down and you restart it again this “waits” will be forgotten. It is really just a bad and temporary hack for short wait times:

And about your problem. You do not paste the code into a function node, you rather click into n8n once and then post it directly into the work flow. It will then automatically create all nodes and connections.

Thanks, Jan. It’s working perfectly.

1 Like

Maybe the bigger picture is related to flow state serialization? Storing flows to disk and then resurrecting them?

I guess that would also help with the “detect change from last state” problem?
Just some random thoughts.

Because not having these two things make things really really complicated at times.

Hello Jan.
If I would like to develop this with for supporting long/undefined waiting times without blocking the thread, how should I do it? Could you give me some idea about how to save the workflow state and resume it afterwards?

Thanks a lot!

2 Likes

Hi jan,

Could we send a request to server to use cron job to use wait time for more stable uptime?
So you just create a node for server request in cron job, support for ssh, api or plesk…

I see you could execute command of server, could we create cron job with id to call again after restart n8n?

Am I understanding this correctly, if “WAIT” gets implemented,

I could do this flow here:

  1. Send 1st email
  2. WAIT 2 days and send 2nd email
  3. Send 3rd email IF user “opened” 2nd email
  4. WAIT 4 days AND send 4th email

??

1 Like

Hey @mikulabeutl!

Theoretically, you are correct. But currently, it is not possible. You can read more about it here: Wait node in workflow [GOT CREATED] - #2 by jan

You could still do that using something like https://www.setcronjob.com/. Of course would not be as easy as having a native wait node.

1 Like

How do you find whether your email is opened or not?

N8n is a workflow automation tool. You need the Email Marketing Tool for this.

correct, n8n is not an email marketing tool, but n8n integrates with email marketing tools or lets you combine tools such as sheets and send email to achieve results too, imagination is key

1 Like

I completely understood. No offense.

Why I’m saying this because.

Imagine you have 1000s of Subscribers. On Day one. You’ll send the first email. Again after 2 days, you’ll send again. Until then n8n will actually be executing the Workflow.

But you can Skip this. I’m not sure.

That’s why I told you “You need Email Marketing Tool”

Interested to know if there is any update on this topic :slight_smile:

2 Likes

Am I right if I say that n8n can’t store different flows for workflows? n8n just go through workflow per each new trigger/request and doesn’t know what was before. It always starts from the first trigger, isn’t it? Like a finite state machine that resets on each new trigger.