Skip to content

Instantly share code, notes, and snippets.

@huyttq
Created November 10, 2011 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huyttq/1354244 to your computer and use it in GitHub Desktop.
Save huyttq/1354244 to your computer and use it in GitHub Desktop.
Using yield to execute
def send_task
self.class.execute { self.prepare!; self }
end
def self.execute
begin
ActiveRecord::Base.connection.execute("LOCK TABLE tasks WRITE")
tasks = [*yield]
ensure
ActiveRecord::Base.connection.execute("UNLOCK TABLE")
end
tasks.each { |task| task.submit_data }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment