JP Silvashy
JP Silvashy

Reputation: 48525

Running a Ruby script outside of my rails app?

I have a script that I want to loop indefinitely outside my rails app, essentially it's just writing values over serial (with the SerialPort library), Can I just us backticks to run my script?

Lastly my biggest concern is that the script will block requests to my rails app while its running. I want it to spawn it's own process, is this possible without using one of these Background job or Workling/Starling solutions?

Upvotes: 1

Views: 547

Answers (2)

cwninja
cwninja

Reputation: 9778

If you have shell access to the box, you can use ./script/runner 'ValueWriter.run' to run any code with the rails environment.

You can use god or monit to ensure this process is running (restart it when it crashes) at all times.

Or one better, include 'config/environment' at the start of your script.

Or one better again, use script/runner, and wrap it in Daemons.

Upvotes: 2

EmFi
EmFi

Reputation: 23450

Launching a program via backticks will block the program that called it. What you're looking for is Drb. This link should cover everything you need to know.

Upvotes: 0

Related Questions