Class: LogicalConstruct::Target::FlightDeck::UniqueProcessTask
- Inherits:
-
Mattock::Rake::Task
- Object
- Mattock::Rake::Task
- LogicalConstruct::Target::FlightDeck::UniqueProcessTask
- Defined in:
- lib/logical-construct/target/flight-deck.rb
Instance Method Summary collapse
Instance Method Details
#action(args) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/logical-construct/target/flight-deck.rb', line 119 def action(args) require 'pathname' Pathname.new(lockdir.absolute_path).mkpath File::open(lockfile.absolute_path, File::CREAT|File::EXCL|File::WRONLY, 0600) do |file| file.write(Process.pid) end at_exit{ File::unlink(lockfile.absolute_path) } rescue Errno::EEXIST pid = File::open(lockfile.absolute_path, File::RDONLY) do |file| file.read.to_i end begin Process.kill(0, pid) puts "Another process (pid: #{pid}) already owns #{lockfile.absolute_path}" puts "Exiting" exit(1) rescue Errno::ESRCH, RangeError #process doesn't exist File::unlink(lockfile.absolute_path) end retry #if we get here it's because the previous process is dead and we've cleaned up end |
#resolve_configuration ⇒ Object
113 114 115 116 117 |
# File 'lib/logical-construct/target/flight-deck.rb', line 113 def resolve_configuration lockfile.relative_path ||= [task_name, "lock"].join(".") resolve_paths super end |