I''m trying to run an external Ruby script from my Rails app.
To do this i''m using this function
def fork_with_new_connection(config, my_class = ActiveRecord::Base)
pid = fork do
begin
my_class.establish_connection(config)
yield
ensure
my_class.remove_connection
end
end
Process.detach(pid)
end
Then, within my controller I do this:
# fork a process
config = ActiveRecord::Base.remove_connection
fork_with_new_connection(config) {
@environment = (RAILS_ENV == ''development'') ?
''dev'' : ''prod''
system("ruby ./public/utils/delicious_import.rb -u #{@user} -p
#{@pass} -r #{@rating} -d #{current_user} -e #{@environment}")
}
ActiveRecord::Base.establish_connection(config)
I have two questions. First, is this the proper/correct way to run an
external script from a rails controller. I just want to fire off the
script and continue; I don''t want to wait around for its completion or
status.
Second, when I do this, my mongrel.pid file seems to be deleted as soon
as the child process completes. It looks like the child process''s
parent is a mongrel_rails process (which makes sense since I am running
mongrel), but then when the process dies, it also removes the
mongrel.pid file from my log/ directory.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Philip Hallstrom
2007-Jan-12 23:50 UTC
Re: Forking a process in Rails is messing up mongrel
> I''m trying to run an external Ruby script from my Rails app. > > I have two questions. First, is this the proper/correct way to run an > external script from a rails controller. I just want to fire off the > script and continue; I don''t want to wait around for its completion or > status.Don''t know about fork, but whenever external scripts come up, everyone recommends looking at backgrounddrb: http://backgroundrb.rubyforge.org/ -philip> > Second, when I do this, my mongrel.pid file seems to be deleted as soon > as the child process completes. It looks like the child process''s > parent is a mongrel_rails process (which makes sense since I am running > mongrel), but then when the process dies, it also removes the > mongrel.pid file from my log/ directory. > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Craig, please read this: http://rubyforge.org/pipermail/mongrel-users/2006-August/001207.html Not sure if it''s relevant, but might help. Vish On 1/13/07, Philip Hallstrom <rails-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > > I''m trying to run an external Ruby script from my Rails app. > > > > I have two questions. First, is this the proper/correct way to run an > > external script from a rails controller. I just want to fire off the > > script and continue; I don''t want to wait around for its completion or > > status. > > Don''t know about fork, but whenever external scripts come up, everyone > recommends looking at backgrounddrb: http://backgroundrb.rubyforge.org/ > > -philip > > > > > > Second, when I do this, my mongrel.pid file seems to be deleted as soon > > as the child process completes. It looks like the child process''s > > parent is a mongrel_rails process (which makes sense since I am running > > mongrel), but then when the process dies, it also removes the > > mongrel.pid file from my log/ directory. > > > > -- > > Posted via http://www.ruby-forum.com/. > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---