Sha256: 339c55171bd1d81b45464ffa8df9d16e0eb4594d1ce7bb624431fa956eda379e

Contents?: true

Size: 479 Bytes

Versions: 5

Compression:

Stored size: 479 Bytes

Contents

# Copyright (c) 2012, SoundCloud Ltd., Tobias Bielohlawek

require 'fileutils'

# Simple locker to make sure  no second process is running in paralell
module MassiveSitemap
  LOCK_FILE = 'generator.lock'

  def lock!(&block)
    if block
      raise Errno::EACCES if ::File.exists?(LOCK_FILE)
      ::File.open(LOCK_FILE, 'w', ::File::EXCL)
      begin
        block.call
      ensure
        FileUtils.rm(LOCK_FILE) #unlock!
      end
    end
  end
  module_function :lock!
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
massive_sitemap-2.1.1 lib/massive_sitemap/lock.rb
massive_sitemap-2.1.0 lib/massive_sitemap/lock.rb
massive_sitemap-2.0.0 lib/massive_sitemap/lock.rb
massive_sitemap-2.0.0.rc8 lib/massive_sitemap/lock.rb
massive_sitemap-2.0.0.rc7 lib/massive_sitemap/lock.rb