Mimicking a batch job or a setInterval setup

Hi All,
I am trying to mimic a continuously running scheduler/batch process or a setInterval method that runs every 20 seconds and checks the DB for any outstanding records. If there are, it processes them and then waits for 20 seconds before starting over.

The above is the setup i have which achieves what i want. I just want to post it out there to see if there is a better way to do it . I am also not sure of the memory footprint for this setup. I also clear the payload in the msg object that i used for storing db records.
The above is not a working version. But an outline of what i want to achieve.

Any thoughts would be beneficial.

runs every 20 seconds and checks the DB for any outstanding records
...
I just want to post it out there to see if there is a better way to do it

What is an "outstanding record" ? This sounds more like something you could solve directly in the database itself ?

Can't you use an inject node set to fire every 20 seconds to run the flow?

There are 2 node.js processes. 1 REST service will accept inbound requests and insert into the DB.
The 2nd process is the node-red process that acts as a scheduler and process those inserted records.

There is a possibility that a single fetch from the DB would be 20 records. The processing for 20 records might take more time. Thats why injecting every 20 seconds constantly irrespective of whether the previous flow ended, will not work in this case.

Something like a recurring setTimeout than a setInterval

Does processdbrecords write back to the database?

Yes. It does write back to DB. So the processed record doesnt get picked up next time.

The flow you suggest looks a reasonable way to go, why are you concerned about the memory footprint?

1 Like

Its just that, the process keeps running continuously unlike conventional rest service which wakes up only by incoming requests. Just worried if the node-red process will ever have time free for garbage collection. Wanted to know if there is a better way out there.

It won't be running continuously, you have 20 second gaps in it. Anyway, the garbage collection will happen if it needs to, holding up the flow if necessary.

1 Like

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