I have a rails app that runs on parallel with a ruby script. This is script is a ruby-mqtt
subscriber, basically it listens for messages over the mqtt protocol and then interacts with the rails app.
The problem is that foreman starts this process simultaneously with the rails server and when there are messages being broadcast and the server has not finished it's startup process, the script crashes, and foreman kills the server with it.
This is the example Procfile:
server: rails s -p 3000 -b 0.0.0.0
mqtt_subscriber: ruby ./mqtt/subscribers/mqtt_subscriber.rb
The current workaround is to run the rails server and when it finishes start up, launch the subscriber from another terminal or using screen.
Is there a way to run the subscriber processes after the server has completely started through foreman start?
You can use the wait-for-it bash script to wait for a tcp port to become available, before the mqtt subscriber starts