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?

Hi Robert Matei

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

Sijo

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:

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"