How to share tables between Ruby Apps

Hi,

We are in the process of rewriting our intranet applications in Ruby.
We have one complete that requires an email invite being sent. We want
to write another app that simply looks for unsent emails and sends
them. This will be used by several ruby apps. How can we share this
table(email details) across several Ruby apps?

Thanks,
GARY LACKERMAN
Software Developer

How can we share this
table(email details) across several Ruby apps?

Sharing a table is straight forward. If they are in the same database,
you simply call the class methods for this utility functionality. If
the table exists in another database, you add that database to the
database.yml file.

More importantly however, you want to avoid code duplication. You do
not want to duplicate the code that looks for unsent emails in all
your apps. You have several options. The first ones that come to mind
are:

  1. Write a utility rails app that does the looking for unsent emails
    and sending. All your other apps simply write to the table that stores
    these unsent emails. With this approach you can build views that allow
    you to see the queue, etc of all the emails, regardless of the app.

  2. If you prefer to have the methods available in each app, then you
    want to look at the plugins facility in rails. You can write a plugin
    that gets used by all your apps. Then each of your apps gets the
    plugin from the same repository.

LaughingNinja wrote:

Software Developer

You could create a message queue in a shared database of some sort. All
applications insert their “to send” emails into the message queue
(database table) and a regular job starts up and reads in the details
and tries to send them. If it manages to send it, it cleans up for this
record (i.e, deletes the item from the table and/ or informs someone).
If it doesn’t manage to send the email, it increments some sort of
“retry count” in the database and waits again. If a message fails to go
after a certain number of tries, it simply marks the message as
undeliverable and removes it from the message queue to a “failed items”
database.

Now, I wonder if there is a message queue implementation in Ruby that
does this?

Cheers,
Mohit.
1/28/2009 | 11:50 AM.