0

i've looked into previous questions which look similar to my problem, nothing seems to be related. After doing the following query:

Runner::Models::Job.where(:id => job_id)

I get an exception, it happens once in a while: Mysql2::Error: MySQL server has gone away: SELECT jobs.* FROM jobs WHERE jobs.id = 7507 LIMIT 1

I use puma, and in config.ru i am using:

use ActiveRecord::ConnectionAdapters::ConnectionManagement

The thing is that this error always happens in the same place, and i cant figure out why is it happening, i've checked memory, cpu, etc'.., all seem normal. Maybe someone will have an idea. thanks !

gal
  • 759
  • 1
  • 12
  • 26

1 Answers1

2

Write your Resque task like this:

class MyTask
  def self.perform
    ActiveRecord::Base.verify_active_connections!
    # rest of your code
  end
end

see more details here: https://github.com/resque/resque/wiki/FAQ#how-do-you-work-around-the-mysql-server-has-gone-away-error-

Andrew Feng
  • 1,912
  • 17
  • 20