Modifying node parameter during the workflow?

Hi,

I run some workflows triggered by interval.

e.g. I set the interval to 60 seconds. But sometimes after processing the data, it’s not necessary to run every 60 seconds and to spend cpu time.

Can I change the interval time automatically in the workflow. e.g. after running a database query ?

Thanks

Hey @passana, the answer here is a bit ambiguous unfortunately. In principle, node parameters can be set via expressions. Here’s a quick example workflow showing the idea:

Example Workflow

The participants value is set via an expression referencing data coming from another node here (which could just as well be a database node instead of the Set node I’ve used).

This will, however, not work for trigger notes like the Interval node, simply because it would be the first node to run in your workflow (and no database result is available yet).

So a possible approach would be to run your Interval node frequently. Then as the first step in your workflow run your database query confirming whether your workflow execution should continue. Add an IF node checking the outcome of your database query and connect your existing workflow to the true output of the IF node.

That way, your workflow would technically still run frequently but the main logic would only be executed when needed.

Thanks @MutedJam

The issue I have is that I have to process a lot of data from time to time and need an interval of 20 seconds to check the database.

That generates a lot of load to the database and n8n and slows down also n8n.

(Although running n8n self-hosted on a server with 16 GB Memory / 320 GB Disk ( Ubuntu 20.04 (LTS) x64), after running some 3-4 workflows with 20 to 30 seconds intervals, n8n gets unresponsive and I had to stop the workflows with cli.)

After processing all the data, the db query gets back 0 results and it does not make sense to run the database query every 20 seconds.

After processing the data, it would be good if I could automatically change the interval without doing a database query every 20 seconds.

I found a workaround via files:

after processing the data I check if record count = 0, then I save the row count to a file. : row_count = 0

The interval node then checks every 20 seconds the file if row = 0 and if true, it stops, otherwise proceeds with a database query, etc.

The workflow that generates data, stores the row_count = 1 to the file, so that the interval knows that it needs to run.

With this workaround the workflows can “communicate” :slight_smile:

I think that the file system is much more efficient, using fewer resources than doing a database query every 20 seconds.

Hopefully, we will be able to store local data in the future.

Thanks for your time

1 Like

That’s a great approach, thanks for sharing! We’re btw working on an official REST API at the moment, so hopefully you will eventually be able to modify your workflows in a fully documented and support way.

Technically you could already copy the REST requests made by the UI when saving changes to a workflow (and use them in an HTTP Request node), but this is undocumented and can change at any point without notice.

1 Like