Skip to content

Instantly share code, notes, and snippets.

@zackham
Created December 21, 2011 22:36
Show Gist options
  • Save zackham/1508031 to your computer and use it in GitHub Desktop.
Save zackham/1508031 to your computer and use it in GitHub Desktop.
class ScheduledReport
include Mongoid::Document
include Mongoid::Timestamps
field :key, :type => String
index :key
field :name, :type => String
field :query, :type => String
field :last_performed_at, :type => DateTime
field :results, :type => Array
def perform
raise 'basic safety check failed' if query =~ /delete from/i or query =~ /update\s/i
self.results = ActiveRecord::Base.connection.select_all(query)
self.last_performed_at = Time.zone.now
save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment