# BackgroundRB for multiple parallel tasks: thread or worker?

**URL:** <https://www.ruby-forum.com/t/backgroundrb-for-multiple-parallel-tasks-thread-or-worker/149779>\
**Category:** Rails\
**Created:** [September 29, 2008, 7:39pm UTC](https://www.ruby-forum.com/t/backgroundrb-for-multiple-parallel-tasks-thread-or-worker/149779 "2008-09-29T19:39:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![javamllama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ce7236/32.png) [@javamllama](https://www.ruby-forum.com/u/javamllama)\
**Post date:** [September 29, 2008, 7:39pm UTC](https://www.ruby-forum.com/t/backgroundrb-for-multiple-parallel-tasks-thread-or-worker/149779/1 "2008-09-29T19:39:47Z")

</div>

I’m just getting started with BackgroundRB, but I’m not sure how to do  
what I need to do.

I have many chat rooms (Jabber) which are controlled or mediated by a  
Rails app. There are periodic elections carried out in these rooms.

Just this would be easy. I could set up a chron job in the configuration  
which gets all the chat rooms from Rails and calls chat.do\_election on  
each (Chat is a model).

However, it is more complicated. Often there is not enough members to  
vote: no quorum. Sometimes the chatters can “recall” a winner with an  
early vote. So each chat room is essentially its own story, with its own  
chronology.

I know what the election\_worker class will look like:

start\_all\_elections()# for create  
trigger\_election(chat\_name)# tell Rails Model chat to do election with  
individual chat  
stop\_voting(chat\_name)# Rails tells election\_worker no quorum  
start\_voting(chat\_name)# quorum is reached  
skip\_to\_vote(chat\_name)# vote is taken immediately, and clock reset,  
when Rails detects a recall

What I DO NOT know is how to deal with these multiple elections. Are  
these THREADS inside the election\_worker class? If so, how would I set  
these up? (I’m new to threads). Or are they multiple instances of  
election\_worker? (Where then would I create multiple instances of the  
worker, since Rails has no “entry point”?)

Thanks, any help appreciated

Matt
