Simple system for asynchronous SQL queries

There has to be something like this… I have some tracking related SQL
queries that are slow and don’t need to happen in the request cycle. Is
it possible to dump them to some text file and then read them in a
daemon and send them to MySQL?

What would be the simplest way of implementing this?

Should note that I already have delayed_job running, but it seems a bit
silly to create a job (in the database) that just executes a SQL query,
even if the SQL query is running take significantly longer than creating
the job.

Robert M. wrote:

There has to be something like this… I have some tracking related SQL
queries that are slow and don’t need to happen in the request cycle. Is
it possible to dump them to some text file and then read them in a
daemon and send them to MySQL?

What would be the simplest way of implementing this?

Hi Robert M.

Can’t you use a rake task and make a cron to execute this task at a
specified time or time interval ?

Sijo

I’d put them in a model and call them via cron, e.g.

in app/models:

class SlowQuery < ActiveRecord::Base
def self.some_query
self.connection.execute “my big slow SQL here”
end
end

cron can call:

ruby script/runner "SlowQuery.some_query"

On Oct 19, 10:26 pm, Robert M. [email protected]

On Mon, Oct 19, 2009 at 7:26 PM, Robert M. wrote:

Should note that I already have delayed_job running, but it seems a bit
silly to create a job (in the database) that just executes a SQL query,
even if the SQL query is running take significantly longer than creating
the job.

And it would be somehow less “silly” to do file IO to "dump them to some
text file and then read them in a daemon and " open a DB connection to
" send them to MySQL?

What would be the simplest way of implementing this?

I’d say you just identified the “simplest”, since it’s already in place.
YMMV :slight_smile:


Hassan S. ------------------------ [email protected]
twitter: @hassan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs