# Threading in ruby/rails

**URL:** <https://www.ruby-forum.com/t/threading-in-ruby-rails/196708>\
**Category:** Rails\
**Created:** [June 10, 2008, 8:42am UTC](https://www.ruby-forum.com/t/threading-in-ruby-rails/196708 "2008-06-10T08:42:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 10, 2008, 8:42am UTC](https://www.ruby-forum.com/t/threading-in-ruby-rails/196708/1 "2008-06-10T08:42:23Z")

</div>

Hi  
I have succesfully send mail from my rails application…I did it like  
below.What I am doing is send a mail to an assignee.  
def after\_transfer  
code--------  
code------  
send\_mail\_to\_primary\_assignee(assignee\_id)  
end

#This is the function responsible for sending mails  
def send\_mail\_to\_primary\_assignee(contact\_id)  
contact\_name=Contact.find(contact\_id).name  
official\_email\_ids =  
ContactEmailAddress.find\_all\_by\_contact\_id(contact\_id ,:conditions =\>  
“contact\_email\_address\_type\_id = ‘2’” )  
official\_email\_ids.each do |official\_email|  
ServiceDeskMailer.deliver\_to\_send\_mail\_to\_primary\_assignee\_on\_transfer\_reason(official\_email,contact\_name)  
end  
puts "```````````````````` "  
end

Then my question is how can i put this to seperate thread in ruby…Why I  
am asking this is only after all the mails are send i can continue in  
the view…So if I put this to a thread is that problem solved .Since I  
am new thread especially in ruby could you please tell me how i can  
implement that?

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 10, 2008, 11:37am UTC](https://www.ruby-forum.com/t/threading-in-ruby-rails/196708/2 "2008-06-10T11:37:07Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Tuesday 10 June 2008 08:42:23 Sijo Kg wrote:

> Then my question is how can i put this to seperate thread in  
> ruby…Why I am asking this is only after all the mails are send i can  
> continue in the view…So if I put this to a thread Â is that problem  
> solved .

Not really – you just push the problem further down the request chain.  
Your request handler can’t complete and pick up a new request until the  
mail handling thread completes. In production, this will probably be  
unacceptable.

Search the Google Group for backgroundrb, starfish and a4r. This has  
been discussed here at least twice in the last week. 🙂

Ciao,  
Sheldon.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.6 (GNU/Linux)

iD4DBQFITksDpGJX8XSgas0RAngkAJMGAbxxlkZZWopd0h90CnNZXsqjAJ9Mpr+3  
/uZaCIPYN3VPphqxnhdttQ==  
=oZss  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 10, 2008, 11:46am UTC](https://www.ruby-forum.com/t/threading-in-ruby-rails/196708/3 "2008-06-10T11:46:08Z")

</div>

Hi  
Thanks for your reply…Meanwhile I was trying with BackGroundrb  
pluggin installed like  
script/plugin install svn://rubyforge.org//var/svn/backgroundrb

But getting error when trying to start that  
[sijo@sijo backgroundrb]$ ./start  
./…/…/config/…/lib/workers/billing\_worker.rb:6: undefined method  
`set_worker_ name' for BillingWorker:Class (NoMethodError) from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in`gem\_o  
riginal\_require’  
from  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `requi re' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/ dependencies.rb:495:in`require’  
from  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active\_support/  
dependencies.rb:342:in `new_constants_in' from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/ dependencies.rb:495:in`require’  
from ./start:72  
from ./start:72:in `each’  
from ./start:72

What might be the reason

Thanks in advance  
Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 10, 2008, 1:19pm UTC](https://www.ruby-forum.com/t/threading-in-ruby-rails/196708/4 "2008-06-10T13:19:56Z")

</div>

Hi  
I here again tried installing Backgroundrb like  
svn co [http://svn.devjavu.com/backgroundrb/tags/release-0.2.1](http://svn.devjavu.com/backgroundrb/tags/release-0.2.1)  
/vendor/plugins/backgroundrb

And succed.But now when i did  
ruby script/backgroundrb start  
It gives the error  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require': no such file to load -- daemons (LoadError) from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
from  
/home/sijo/railsexamples/mailexamples/mailing/vendor/plugins/backgroundrb/server/lib/backgroundrb\_server.rb:2  
from script/backgroundrb:27:in `require’  
from script/backgroundrb:27

Could you please tell me what the reason is?

Sijo

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 10, 2008, 2:58pm UTC](https://www.ruby-forum.com/t/threading-in-ruby-rails/196708/5 "2008-06-10T14:58:53Z")

</div>

Not sure if this is it, but it seems to be saying there’s a gem called  
daemons missing?

sudo gem install daemons

On Tue, Jun 10, 2008 at 7:19 PM, Sijo Kg  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## `gem\_original\_require’: no such file to load – daemons (LoadError)
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ramon T.

---

<div class="post-metadata">

**Author:** ![sijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@sijo](https://www.ruby-forum.com/u/sijo)\
**Post date:** [June 10, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/threading-in-ruby-rails/196708/6 "2008-06-10T15:16:01Z")

</div>

On Tue, Jun 10, 2008 at 4:49 PM, Sijo Kg  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> `gem_original_require': no such file to load -- daemons (LoadError) from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
> from  
> /home/sijo/railsexamples/mailexamples/mailing/vendor/plugins/backgroundrb/server/lib/backgroundrb\_server.rb:2  
> from script/backgroundrb:27:in `require’  
> from script/backgroundrb:27
> 
> Could you please tell me what the reason is?

Any reasons for using such an ancient version of backgroundrb?

Checkout:

[http://backgroundrb.rubyforge.org](http://backgroundrb.rubyforge.org)

Also, i am getting backgroundrb for a new release and instructions for  
running code from git is here:

[http://gnufied.org/2008/05/21/bleeding-edge-version-of-backgroundrb-for-better-memory-usage/](http://gnufied.org/2008/05/21/bleeding-edge-version-of-backgroundrb-for-better-memory-usage/)

Mant find git version much more stable than svn, so please try that  
other than anything else. Also, there is a mailing list for  
backgroundrb, which you can use for posting queries.
