lib/shelr/publisher.rb in shelr-0.12.2 vs lib/shelr/publisher.rb in shelr-0.12.3

- old
+ new

@@ -3,10 +3,11 @@ module Shelr class Publisher def publish(id) + ensure_unlocked(id) with_exception_handler do uri = URI.parse(Shelr::API_URL + '/records') params = { 'record' => prepare(id) } params.merge!({'api_key' => Shelr.api_key}) if api_key handle_response Net::HTTP.post_form(uri, params) @@ -21,9 +22,20 @@ STDOUT.puts "=> record dumped to #{dump_filename}" end end private + + def ensure_unlocked(id) + lock_path = File.join(Shelr.data_dir(id), 'lock') + if File.exist?(lock_path) + puts "=> Cannot publish" + puts "=> Record locked on #{File.read(lock_path)}" + puts "=> Esure no other shelr process running" + puts "=> Or remove lock file manually: #{lock_path}" + exit 0 + end + end def with_exception_handler(&block) yield rescue => e STDOUT.puts "=> Something went wrong..."