javascript - Ruby on rails - How to make controller execute 2 actions simultaneously with ajax? -


i calling 2 different actions same controller ajax in development environment. in 1 action updating database in slow process. on other action want percentual concluded update progressbar. can see both executing, problem second action waiting first finish execute , should executing every second actual percentual. can rails execute 2 actions in parallel? or webrick problem?


i tried puma suggested it's still waiting first action, heres ajax code call

$(document).ready(function() { $(':button').click(function(){     var formdata = new formdata($('form')[0]);     $.ajax({         url: '/quotes/upload',  //server script process data         type: 'post',         //ajax events         beforesend: progress,         success: completehandler,         error: function(ts) { alert(ts.responsetext) },         // form data         data: formdata,         //options tell jquery not process data or worry content-type.         cache: false,         contenttype: false,         processdata: false     }); }); });  function progress() { $.ajax({     url: '/quotes/status.json',     datatype: "json" }).success(function (percentual) {     if (percentual >= '95') {         location.reload();     } else {         var $bar = $('.bar');         $bar.width(percentual+"%");         setinterval(progress,800);     } }); } 

and here console print out:

started "/quotes/status.json" 127.0.0.1 @ 2014-09-21 10:23:38 -0300 processing quotescontroller#status json   percentual => 0 completed 200 ok in 4ms (views: 0.6ms | activerecord: 0.0ms)   started post "/quotes/upload" 127.0.0.1 @ 2014-09-21 10:23:38 -0300 processing quotescontroller#upload */* parameters: {"quotes"=>#<actiondispatch::http::uploadedfile:0x00000001b980b0    @tempfile=#<tempfile:/tmp/rackmultipart20140921-5849-otvxky>, @original_filename="hist_xxx.txt", @content_type="text/plain", @headers="content-disposition: form-data; name=\"quotes\"; filename=\"hist_xxx.txt\"\r\ncontent-type: text/plain\r\n">}   rendered quotes/index.html.erb within layouts/application (0.7ms)  completed 200 ok in 10456ms (views: 170.3ms | activerecord: 0.0ms)   started "/quotes/status.json" 127.0.0.1 @ 2014-09-21 10:23:49 -0300 processing quotescontroller#status json   percentual => 100 completed 200 ok in 3ms (views: 0.4ms | activerecord: 0.0ms) 

as can see console making first call before upload, it's making upload, then, after finishing making second call status

you're correct - webrick process 1 request @ time. perhaps give thin, puma or unicorn go - handle concurrent requests.

note: be advised using sqlite can have similar concurrency issues (especially if writes involved!) switch postgesql or mysql.


to use thin:

gemfile

gem 'thin' 

of course...

bundle install 

then start server

thin start 

to use puma:

gemfile

gem 'puma' 

of course...

bundle install 

to start server

rails s puma 

to use unicorn:

gemfile

gem 'unicorn' 

of course...

bundle install 

to start server

unicorn_rails 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -