I am developing an app that updates products in Shopify. On the React front end, the user can "Activate" the app and run the logic that checks and updates every product in their online store.
I'm also running a cron-job at night that runs the same process to update the user's products.
This process can take up to 10+ minutes so I'm returning a 202 response immediately.
Here's the problem: If the user "Activates" the app while the cron-job is running, then I get throttled by Shopify for hitting their API too many times (2 identical product updating processes running side by side).
What I'm struggling to create is a system that prevents the user on the front end from running the process if A) the cron-job is running or B) they already activated it and it's running.
Basically, if backend process is running, prevent the user from being able to activate it.
Any thoughts on how to best approach this?
Through my research, I'm considering the following solution:
Adding a column in my DB for "can_activate." Whenever the process starts, it updates the DB to false. Then at the end it sets the DB to true. Then I'll use polling from node to DB to check when it updates. From node to React I'll use websockets to check and update state that prevents the button from being clickable or not.
Am I overcomplicating this?