Created
November 10, 2011 06:14
-
-
Save huyttq/1354244 to your computer and use it in GitHub Desktop.
Using yield to execute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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