I am working on uber like/cab booking app. I am using Action Cable for this purpose. After creation of new order server get list of 10 nearest drivers and send each in turn order details (with a pause of 40 seconds).
Thread.new do
nearest_drivers.each do |id|
order_data_for_driver = { ... }
ActionCable.server.broadcast("driver_#{id}", order_data_for_driver)
sleep 40
Thread.exit if order.reload.canceled_by_user || order.trip
end
cancel_data = {canceled_by_timeout: true }
ActionCable.server.broadcast("order_#{order.id}", cancel_data )
end
Is there a limit to the number of threads that rails in production mode can run at the same time? For example, if 100 users will create new orders. What more elegant solution can be used?