Sha256: 7eeb2b0c3a5aab3d7c2da25f8378b4c3dd7d61c21f5d5ccb985fe8ffef15bb40
Contents?: true
Size: 801 Bytes
Versions: 38
Compression:
Stored size: 801 Bytes
Contents
ENV["DB"] = "postgres" require "thread" require File.expand_path("../../../helper", __FILE__) require "active_record/locking/fatalistic" ActiveRecord::Migration.tap do |m| m.drop_table "things" m.create_table("things") do |t| t.string :name t.string :slug end m.add_index :things, :slug, :unique => true end class Thing < ActiveRecord::Base extend FriendlyId friendly_id :name, :use => :slugged end $things = 10.times.map do Thing.new :name => "a b c" end $mutex = Mutex.new def save_thing thing = $mutex.synchronize do $things.pop end if thing.nil? then return end Thing.lock do thing.save! print "#{thing.friendly_id}\n" end true end 2.times.map do Thread.new do while true do break unless save_thing end end end.map(&:value)
Version data entries
38 entries across 33 versions & 4 rubygems