Based on an external redis queue, I want a Sinatra application to run a script like this:

ruby fetch_vin.rb vin_number_123

This will fire up watir-webdriver and report to the queue appropriately. When the script is finished, everything but the Sinatra app should close.

It seems however that Thread, as well as exec and spawn are all blocking when ran from inside ruby.

How do I fire & forget?

Ответы (1)

You can use Process#spawn:

pid = Process.spawn("ruby fetch_vin.rb vin_number_123")

I think the bit you were missing was calling detach after the process was spawned. This will detach and let both processes continue to run. Will work for any command, not just a ruby script.

See Process Ruby Docs for more details.

2022 WebDevInsider