Change the value of a variable inside a running ruby program

I have a program that is running constantly and I’d like to be able to
change the value of a variable inside it from the outside by doing
something on the command line.

Ideally, this would happen via an interrupt process so that the program
doesn’t have to continuously poll some resource.

Right now, the program just polls mysql every few seconds to see if
someone has changed a setting which is stored in a table. Ideally, I’d
like the program to read from the table on startup but then not have to
poll mysql anymore to see if the setting has been changed.

Hopefully I’m making sense here…

On Thu, Apr 12, 2012 at 6:38 PM, Matthew S. [email protected]
wrote:

I have a program that is running constantly and I’d like to be able to
change the value of a variable inside it from the outside by doing
something on the command line.

Ideally, this would happen via an interrupt process so that the program
doesn’t have to continuously poll some resource.

Module: Signal (Ruby 1.9.3) ?

On 13/04/12 13:38, Matthew S. wrote:

poll mysql anymore to see if the setting has been changed.

Hopefully I’m making sense here…

Could you just use a HUP, SIGUSR1 or 2 signal handler to set the flag?
Either it causes the app to reread the value from the database, or if it
is just a toggle/ dual state item, simply switches it based on which
signal it gets?

Sam

On Thu, Apr 12, 2012 at 8:38 PM, Matthew S. [email protected]
wrote:

poll mysql anymore to see if the setting has been changed.

Hopefully I’m making sense here…


Posted via http://www.ruby-forum.com/.

You might be able to use DRb to expose those settings (I don’t know much
about it, but this seems like the kind of thing it could do).