You can clone with
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
alias_method :execute_without_retry, :execute
rescue ActiveRecord::StatementInvalid => e
if e.message =~ /server has gone away/i
warn "Server timed out, retrying"