[Backgroundrb-devel] multiple database design question

Woody Peterson woody at crystalcommerce.com
Thu Aug 14 15:02:28 EDT 2008

Hi all. I have a few questions, but I'll start a thread per question.  
My first is a design issue that's fairly specific to my application,  
but I thought someone might be willing to give out some insights.

My application has multiple databases, one per client, and I hijack  
the database connection at the beginning of a request and connect it  
to the appropriate database. So, I have to pass the database to any  
workers so that they know which database to operate on. I have two  
choices here:

1) Have a single worker, pass in the database to all worker methods,  
and have the method connect to the correct database before beginning  
the real processing

2) Create multiple workers, one per database, and have them connect to  
the appropriate database when initialized via the 'create' method.  
Rails can then call methods on the appropriate database specific  
worker. without having to pass the database in to each method,  
although it will have to use the database as a worker key when getting  
the correct worker.

I like the organization of the second method, but the simplicity of  
the first. I'm thinking I'll go with the first. Any thoughts?

More information about the Backgroundrb-devel mailing list