On Dec 9, 2:34 am, Gerhard <[email protected]> wrote:
> 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/f4e5c...
>
> 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.

I mentioned this to Gerhard privately, but for the sake of the
archives, while this solution works in Gerhard's case, it's not a
generic solution to the problem.  You need to be sure that your begin/
rescue block is idempotent if you are going to be automatically
retrying.  In this case, that appears to be true (it's a simple
select), but it's probably not true in general.

Jeremy

-- 
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