module MailEngine::RakeLocker
Constants
- TRY_TIMES
Public Instance Methods
lock_task() { || ... }
click to toggle source
# File lib/mail_engine/rake_locker.rb, line 5 def lock_task raise "Please pass block." unless block_given? if locked? puts 'locked!' lock else lock yield unlock end end
Private Instance Methods
lock()
click to toggle source
# File lib/mail_engine/rake_locker.rb, line 30 def lock (1..TRY_TIMES).each do |n| unless FileTest.exist? "#{Rails.root}/tmp/convert_files_lock#{n}" `touch #{Rails.root}/tmp/convert_files_lock#{n}` break end end end
locked?()
click to toggle source
# File lib/mail_engine/rake_locker.rb, line 20 def locked? # if no convert_files_lock1, not locked return false unless FileTest.exist? "#{Rails.root}/tmp/convert_files_lock1" # if no convert_files_lock4, return locked return true unless FileTest.exist? "#{Rails.root}/tmp/convert_files_lock#{TRY_TIMES}" ### tried TRY_TIMES times, found convert_files_lock4 file, unlock it unlock_task return false end
unlock()
click to toggle source
# File lib/mail_engine/rake_locker.rb, line 39 def unlock `rm #{Rails.root}/tmp/convert_files_lock*` end