This is related to an older discussion that I started a while back. I
couldn't add another message there, so I'm posting here the solution.
The original thread can be found here:
http://groups.google.com/group/sequel-talk/browse_thread/thread/f4e5c73989685d50

To provide more context, I'm using Sequel connections within a
periodic resque job that syncs some MySQL records with MongoDB ones.

When the app boots (parent workers load), I run the following (part of
the init):

  Sequel::Model.db = Sequel.connect(mysql_options)

In one of the mongo models, I have a mysql method that gives me access
to the MySQL equivalent of that model. It used to look like this:

  def mysql
    @mysql ||= MysqlSite[self.id]
  end

This was raising a Sequel::DatabaseDisconnectError, and even though
Sequel would create a new connection on a subsequent query, because it
runs within a resque job, this job would keep failing even if MySQL
came back up. This solved my problem:

  def mysql
    @mysql ||= begin
      MysqlSite[self.id]
    rescue Sequel::DatabaseDisconnectError
      retry
    end
  end

If MySQL is down, the jobs keep failing (a new one gets triggered
every n minutes). When MySQL comes back up, all subsequent jobs work
as expected, including initially failed jobs that get retried.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to