Rails display progress bar while running query
Asked Answered
M

1

6

I have a couple of MySQL queries that take a really long time and I'd like to display a progress bar while they are running. Is this possible in Rails with maybe jquery? Does ActiveRecord have any mechanisms for this?

Really? No ideas? Then how about this:

I have the queries separated by line,(connection.execute) can I call something that would resemble a progress bar between query calls?

Muraida answered 19/12, 2011 at 9:23 Comment(0)
A
0

This is not a problem. Make a wrapper for execute query, for example:

def execute_sql(sql_string)
  results = []
  ActiveRecord::Base.transaction do
    sql_string.split(';').each do |sql_query|
      if sql_query.present?
        result = ActiveRecord::Base.connection.execute(sql_query)
        results << result if result
        your_progress = results.length
      end
    end
  end
end
Aristippus answered 1/8, 2016 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.