From 8bf8a6b0494faef24d9c413833d274b152ec0b6e Mon Sep 17 00:00:00 2001 From: root Date: Wed, 19 Dec 2012 17:07:31 +0000 Subject: adjustments for production server --- Gemfile | 4 ++++ aop.gemspec | 1 + application.rb | 14 +++++++++++--- unicorn.rb | 3 ++- views/layout.haml | 4 ++++ 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index f98dbde..019cd49 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,6 @@ +if RUBY_VERSION =~ /1.9/ + Encoding.default_external = Encoding::UTF_8 + Encoding.default_internal = Encoding::UTF_8 +end source :gemcutter gemspec diff --git a/aop.gemspec b/aop.gemspec index 6b2fe3c..bcc0184 100644 --- a/aop.gemspec +++ b/aop.gemspec @@ -28,5 +28,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency "rest-client" s.add_runtime_dependency "rest-client-components" s.add_runtime_dependency "memcache-client" + s.add_runtime_dependency "unicorn" end diff --git a/application.rb b/application.rb index 6eac935..b065a58 100644 --- a/application.rb +++ b/application.rb @@ -123,7 +123,7 @@ class Application < Sinatra::Base end after '/pug/*' do - CACHE.add request.path, @result, 7200 + CACHE.add request.path, @result, 72000 if @result end before '/cid/:cid/*' do @@ -136,6 +136,9 @@ class Application < Sinatra::Base get '/cid/:cid/?' do @cid = params[:cid] + #local("/pug/cid/#{@cid}/predictions") + pid = Process.fork{ local("/pug/cid/#{@cid}/predictions") } + Process.detach pid haml :compound end @@ -144,8 +147,9 @@ class Application < Sinatra::Base if !@cids or @cids.empty? haml :not_found elsif @cids.size == 1 - @cid = @cids.first - haml :compound + redirect to("/cid/#{@cids.first}") + #@cid = @cids.first + #haml :compound else haml :select end @@ -218,7 +222,11 @@ class Application < Sinatra::Base end get '/pug/name/:name' do + begin @result = RestClient.get(File.join(PUG_URI,"compound","name",CGI.escape(params[:name]),"cids","TXT")).split("\n").to_json + rescue + @result = nil + end end get '/pug/cid/:cid/image' do diff --git a/unicorn.rb b/unicorn.rb index 59b9883..c0441ab 100644 --- a/unicorn.rb +++ b/unicorn.rb @@ -1 +1,2 @@ -timeout 600 +worker_processes 6 +timeout 6000 diff --git a/views/layout.haml b/views/layout.haml index 8ca6a2d..9b423fd 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -3,11 +3,13 @@ %head %script{:type => "text/javascript", :src => "/jquery-1.8.2.js"} :javascript + $(document).ready(function() { $.ajax({ url: "/cid/#{@cid}/experiments", cache: true }); }); function show(title,element,uri) { $(element).html("

"+title+"

"+"Retrieving data from PubChem. This may take some time, please be patient."+"\"Searching"); $.ajax({ cache: true, url: uri, + //timeout: 120000; success: function(data){ data = "

"+title+"

"+"" + data; $(element).html(data); @@ -28,6 +30,7 @@ $.ajax({ cache: true, url: uri, + //timeout: 120000; success: function(data){ $(element).html(data); }, @@ -44,4 +47,5 @@ %label{:for => 'name'} Compound name: %input{:type => 'text', :name => 'name', :id => 'name'} %input{ :type => "submit", :value => "Search" } + %em This is an experimental version. Loading data from PubChem can be slow. Please use the "Back" button and retry the offending operation if you have timeout problems. = yield -- cgit v1.2.3