<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Viamentis Blog &#187; mutitask</title>
	<atom:link href="http://blog.viamentis.com/articles/tag/mutitask/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.viamentis.com</link>
	<description>Curious About Everything</description>
	<lastBuildDate>Mon, 12 Jul 2010 11:16:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>BackgrounDRb a ruby library along with rails</title>
		<link>http://blog.viamentis.com/articles/2008/04/25/backgroundrb-a-ruby-library-along-with-rails/</link>
		<comments>http://blog.viamentis.com/articles/2008/04/25/backgroundrb-a-ruby-library-along-with-rails/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 11:30:29 +0000</pubDate>
		<dc:creator>divya</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[backgroundrb]]></category>
		<category><![CDATA[mutitask]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.viamentis.com/articles/2008/04/25/backgroundrb-a-ruby-library-along-with-rails/</guid>
		<description><![CDATA[Since Rails is single threaded and can&#8217;t handle multiple requests at a time , when I need such functionality I was helpless.Then I came to know about BackgrounDRb a ruby library which will help us to make &#8220;RAILS&#8221; handle multiple requests at the same time.To make use of this library is pretty simple. Following steps [...]]]></description>
			<content:encoded><![CDATA[<p>Since Rails is single threaded and can&#8217;t handle multiple requests at a time , when I need such functionality I was helpless.Then I came to know about <a href="http://backgroundrb.rubyforge.org/index.html">BackgrounDRb</a>  a ruby library which will help us to make &#8220;RAILS&#8221; handle multiple requests at the same time.To make use of this library is pretty simple. Following steps will help you to do so.BackgrounDRb depends on chronic and packet gems. Thus lets get started by installing these two gems first</p>
<p><code>sudo gem install chronic packet</code></p>
<p>Now we are ready to install backgroundrb , for this we need to do</p>
<p><code>script/plugin install svn://rubyforge.org//var/svn/backgroundrb</code></p>
<p>Now backgroundrb plugin is installed on our application, now set it up using the command</p>
<p><code>rake backgroundrb:setup</code>  :this will create three files on our application</p>
<p><code>creates a config file backgroundrb.yml in config directory of your rails application.<br />
Creates RAILS_ROOT/lib/workers directory for keeping BackgrounDRb workers in one place.<br />
Creates RAILS_ROOT/test/bdrb_test_helper.rb as a test helper for your workers</code></p>
<p><code></code><br />
How this helps to balance the load is very interesting. Here we have one class called &#8220;<strong>worker</strong>&#8220;. Using this worker class we can make our time-consuming tasks run in the background of application, instead of running in controller.Now we can create our  worker using the command</p>
<p><code>./script/generate worker &lt;classname&gt;</code> which will generate your worker class and there you can write your time taking process.</p>
<p>Now we can invoke the worker on request using</p>
<p><code>MiddleMan.new_worker :class =&gt; :name_of_your_worker, :args =&gt; {arguments to pass}</code></p>
<p>Before you start your web server do start backgroundrb, you can start and stop this by</p>
<p><code>./script/backgroundrb/start<br />
./script/backgroundrb/stop</code></p>
<p><code></code><br />
Now our app will act as multi threaded. Try an example given below</p>
<p>Let me first thank my colleague Mr.Unni for his code on &#8220;downloading the song from YouTube using a ruby script&#8221;, I am borrowing few parts of it. So in the sample app you can download a song from YouTube using the URL of that particular song. Here Backgroundrb plays well to download multiple songs at same time by running it on background. Run this app on clicking the link below:<br />
<a href="http://blog.viamentis.com/wp-content/uploads/2008/04/background.zip">Download and run me</a></p>
<div id="pfButton"><a href="http://blog.viamentis.com/articles/2008/04/25/backgroundrb-a-ruby-library-along-with-rails/?pfstyle=wp" title="Print an optimized version of this web page"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-button-both.gif" alt="Print"/></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.viamentis.com/articles/2008/04/25/backgroundrb-a-ruby-library-along-with-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
