Skip to content

Instantly share code, notes, and snippets.

@adamwiggins
Created August 28, 2008 19:42
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 adamwiggins/7805 to your computer and use it in GitHub Desktop.
Save adamwiggins/7805 to your computer and use it in GitHub Desktop.
class CreateSemaphores < ActiveRecord::Migration
def self.up
create_table :semaphores do |t|
t.column :name, :text
t.column :value, :integer
end
add_index :semaphores, :name, :unique => true
end
end
Semaphore.lock('lock1', 'lock2') do
# code
end
class Semaphore < ActiveRecord::Base
def self.lock(*keys)
transaction do
keys.sort.map { |key| create!(:name => key).destroy }
yield
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment