Wait node in workflow

I think some flows need wait node.
For example if after some minutes doesn’t occur any(or special) event execute another flow or some specific nodes.

Totally agree! A wait-node would be very important for many use cases. Implementing that properly is sadly not trivial and would take some time. For a short wait time (a few seconds) it would be OK (and best) to simply leave the process running.

That can also be done with a Function-Node already like this:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "const waitTimeSeconds = 3;\n\nreturn new Promise((resolve) => {\n  setTimeout(() => {\n    resolve();\n  }, waitTimeSeconds * 1000);\n});\n\n"
      },
      "name": "Wait",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        802,
        416
      ]
    }
  ],
  "connections": {}
}

For everything longer, it gets more complicated. Then it should save the data of the current workflow to the database, set up some kind of timer in the main process (which also has to handle when the main process gets restarted or is turned off for a longer time) and once the timer fires it has to load the data again from the database and then start the workflow from where it left off.

Because if somebody would, for example, automate some kind of signup flow where it first directly sends a welcome email and then another one a week later it would cause big problems. If such a wait is not implemented correctly there would be a lot of waiting processes that would over time eat up all the RAM and at some point crash the system.

It is definitely nothing impossible but sadly something which has to be thought about properly and done correctly.

1 Like

I think little you tell more.
You are the best my friend.

Thanks a lot!

Hope I will be able to create a proper solution for that soon!

1 Like

Thank you.
I will so.

This is a good thing for me as well. I think a easy way to implement this is to have something in memory or in some storage like:

  • Run task
  • Stop task as status WAITING
  • throw in memory that a task exist and it’s in waiting
  • Check storage to see if there is anything in the queue
  • If there is, run
  • If there is not, wait for the “checker” to be called again
  • fun checker every 30s or so and to that as the smallest timeframe (You can configure the timeframe as well)
  • If it checked more than 5 times (configurable in the screen), just say it didn’t work

I don’t know if something like this is possible, but that’s how i did something like that for a client once

This can be a good solution for a trigger that i want. Everytime a new line is introduced to google sheets, call the task. Today i will do that in lambda e call n8n via webhook. But this loop thing can be a good way to implement the new line in Google sheets.

How did you add the trigger for google sheet when a new row is inserted in google sheets.

What do you mean exactly? How you would program one or how to do it currently? Because no such functionality exists yet.

I meant to say that , i want to listen for google sheet insertion event . Is there any way to do that ?

No currently no such trigger exists yet.

So how can i program it manually , do i need to write a custom backend service(that will be an webhook api) so that i can use that as a webhook trigger ?

Did not have time yet to try if it works but I think that one could work:
https://developers.google.com/drive/api/v3/reference/changes/watch

I had planned to use that one for a Trigger-Node if it does, at least as soon I find some time. For you to test, you can simply create a Webhook-Node, get its URL, and then add it as watch to Google manually. The workflow should then normally execute whenever you make a change.

It would be great if you could inform me if you tried it and if it worked.