Thursday, 18 May 2017

Multiple processes polling mysql and updating data

I am having an issue with getting mysql and my nodejs app to play along nicely together. Basically, I have two nodejs "clients" that poll mysql table for 50 rows of data. However, I do not want them to poll the same 50 rows. Once one client has it's 50 rows of data, it performs some basic operations and spins up some bash scripts. It may take a few seconds for this. All 50 rows of data are updated in the table to indicate those rows are "in-use" on that client.

The problem is, there are situations where both clients request at the same time and receive the same 50 rows. How do/Can I safely use an innodb lock to lock those rows from being read/used by any other client? Even when it may take a few seconds to make sure the row data has successfully spun up the scripts?

I'm sort of at a loss and need some pointers.



via Jerry

No comments:

Post a Comment