How to show time on output

hello!, I made a javascript function to vary the response time in a node “function” is working properly, my question is: how do I show the time value assigned by the function? for me to know what was the time it generated

Uh before answering the question. Did you check out the Wait-Node and setting an expression on the wait-time? Because your above approach will mean that the execution stays active the whole time which is not great for memory consumption.

yes, I used wait-node, but two things happened: 1- in the workflow, after 180 repetitions, it entered a loop and didn’t move forward in the flow; 2- could not put variable time.

so I preferred to use function-node.

Do not understand issue 1. It should if the wait time is longer than 65 seconds put it to sleep to not use any resources. Which is a feature not a bug. And 2. why can you not put a variable time in there?

actually the waiting time is from 1 minute or 60000 milliseconds, I put 1000 milliseconds in this “function-node” just to make the execution faster. I don’t know how to put “wait-node” to sleep; I also don’t know how to put variable time in “wait-node”. That’s why I created the “function-node” to create the time that varies between 1 minute and 5 minutes, and it’s working perfectly. now I would just like, if possible, to see what is the value he defined in “const =time”

this is my complete workflow:

You can set a variable time on the Wait-Node by setting an expression on the parameter “Wait Amount”.

Anyway, you are obviously free to do whatever you want, just saying it is a bad idea.

Here your extended Function-Node code to do what you want:

const tempo = Math.floor(Math.random() * 5) + 1;
console.log(tempo);
const waitTimeSeconds = tempo;

return new Promise((resolve) => {
    setTimeout(() => {
    resolve(items.map(item => {
      return {
        json: {...item.json, tempo},
        pairedItem: item.pairedItem,
      }
    }));
  }, waitTimeSeconds * 60000);
});

Thank you, it worked perfectly

I also made a wait node with putting the parameters in “await-amount” as you suggested and it worked well too, I even thought of using the wait node instead of the function, but as in this flow it hangs around 180 repetitions, so I I preferred to keep the function node the same

If n8n crashes after 180 repetitions with the Wait-Node, then it will very likely crash with the Function/Code-Node even earlier because of the way they work (duplicating the incoming data + executions staying in memory the whole time).

Generally do you have to be aware that you can not have something running forever. Each node that executes increases the memory required, at some point the memory available will be smaller than the required one and then it crashes. So would then be better to split it up into different executions.

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