Nuno Job
2009-Apr-28 14:52 UTC
[Eventmachine-talk] Calling EventMachine defering a response from
Hi all, This is my first email. I''m a complete newbie in what comes to eventmachine - so please forgive me if I''m saying something foolish. I''m trying to create a webservice to interface a database with on a very restfull way: Something like: - GET / => lists all databases - POST / => creates a new database with name=params[:name] - GET /DB => Gets columns for database named DB The goal of the project is just self-learning so ignore if the solution is over engineered. So I create a sinatra webservice and just created a method to run sql commands (generated from paths): Then I installed a MQ (Rabbit) and set up some vhosts and users ( http://github.com/dscape/DBConnector/blob/f3c12e356a9ecac485dc1fe76300fef2c4d39bae/README ) Then created a simple client that connects to a database, and listen to a queue for that database. If it receives a request it processes and returns it in a different queue for sinatra to pick it up ( http://github.com/dscape/DBConnector/blob/f3c12e356a9ecac485dc1fe76300fef2c4d39bae/dbconnector.rb ) Now the only thing let was sinatras side (line 4, http://github.com/dscape/DB2WebCC/blob/031c1505556533eaf947d509fabb8664d4b57eb2/lib/db2webcc.rb ): - When sql command is ready, publish on queue - Expect for response - Serve it for customer after rendered in the template I''m a newbie but I know that''s terrible code. Can someone tell me how can a person do this from sinatra? Do I need and how can I use defferable? Will my crappy code mistakenly give wrong answers for requests as I''m using the same Queue and some queries take longer than others? To solve it should I use a query live DBNAME.SOMEKEY (unique for query) and subscribe to DBNAME.*? Thanks for the understanding - I''m still learning :) Nuno -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/eventmachine-talk/attachments/20090428/022542d1/attachment.html>
James Tucker
2009-Apr-28 15:36 UTC
[Eventmachine-talk] Calling EventMachine defering a response
On 28 Apr 2009, at 19:52, Nuno Job wrote:> > I''m a newbie but I know that''s terrible code. Can someone tell me > how can a person do this from sinatra? Do I need and how can I use > defferable?This facility is provided by thin 1.2.0+[1] and async_sinatra[2]. There are some limited examples in the repos, in the thin repo see async_*.ru in the example directory, and see the readme in async_sinatra. [1] http://github.com/macournoyer/thin or http://github.com/raggi/thin [2] http://github.com/raggi/async_sinatra> Thanks for the understanding - I''m still learning :) > > Nuno > _______________________________________________ > Eventmachine-talk mailing list > Eventmachine-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/eventmachine-talk