Hi all,
Here is my dilemma. I have a flask webserver and I have a user input where they enter the number of seconds to turn a piece of hardware on for.
Currently,
I send an ajax request to a route in flask where i send a message to turn on the hardware via mqtt... then in flask I time.sleep(user input) and then send an mqtt message to turn off the hardware.
I don't want to have a while loop in my route because it can make it inefficient and cause problems.
So, now I am trying to implement a redis & rq task que system. My problem is one, I have roughly 7 pieces of hardware to turn off and on, the RQ worker only runs one job at a time. So if I try to turn multiple hardware devices at the same time they turn on and off in sequence rather then at the same time. So from my understanding...I must create more workers. One for each piece of hardware. BUT, now my main worry is what if multiple clients are sending requests to turn on/off the hardware at the same time but on different browsers. Does this mean their job will wait for the other persons job to finish before its executed in the que?
Another idea I have is to to subscribe/publish to some new topics on mqtt on the raspberry pi. I would make a topic for each piece of hardware I want to have a timer for.
In the flask route(inside the while loop i mentioned above)...I also poll for the status of the device... So if I turn it on I dont notify that the pump is on until it is confirmed by the raspberry pi (in the form of a callback message over mqtt that updates a dictionary back on the server with the current state). So if anyone has any idea on how to pool for the devices state without using a while loop that would be helpful!
If anyone has any advice on a simple/effective way to do this I would be very grateful. My main goal is to be able to run these pump timers at the same time, be able to pool for their on/off state after the mqtt message is sent without blocking the app with a while loop, and not let other users requests block eachother in the even I was using redis/rq queue system.