Commit 7b5f6d8c733c4753e78832e7da6d7f5556dea7dc
- Date: Mon May 05 19:04:09 +0000 2008
- Committer: Dayne Broderson (dayne@gina.alaska.edu)
- Author: Dayne Broderson (dayne@gina.alaska.edu)
- Commit SHA1: 7b5f6d8c733c4753e78832e7da6d7f5556dea7dc
- Tree SHA1: 65d12329151d00c1a8e47da448e13f6b6488a7cf
Lock file is now a PID lock file - checks for stale lock file & PID
Commit diff
| |   |
| 6 | 6 | LOCK_FILE_PATH = File.join(Dir.tmpdir, "gitorious_task_lockfile") |
| 7 | 7 | ENV["PATH"] = "/usr/local/bin/:/opt/local/bin:#{ENV["PATH"]}" |
| 8 | 8 | |
| 9 | | if File.exist?(LOCK_FILE_PATH) |
| 10 | | $stderr.puts "Task lockfile '#{LOCK_FILE_PATH}' exists!" |
| 11 | | exit(1) |
| 12 | | end |
| 13 | | |
| 14 | 9 | ENV["RAILS_ENV"] ||= "production" |
| 15 | 10 | require File.dirname(__FILE__) + "/../config/environment" |
| 16 | 11 | |
| 17 | | |
| 18 | 12 | class TaskLockError < StandardError; end |
| 19 | 13 | |
| 20 | 14 | def with_lock(&block) |
| 21 | 15 | begin |
| 22 | 16 | if File.exist?(LOCK_FILE_PATH) |
| 23 | | raise TaskLockError |
| 17 | pid = IO.read( LOCK_FILE_PATH ).to_i |
| 18 | if File.directory?("/proc/#{pid}/") |
| 19 | raise TaskLockError |
| 20 | else # STALE LOCK FILE |
| 21 | FileUtils.rm(LOCK_FILE_PATH) |
| 22 | end |
| 24 | 23 | end |
| 25 | | FileUtils.touch(LOCK_FILE_PATH) |
| 24 | File.open(LOCK_FILE_PATH,'w') { |f| f << $$ } |
| 26 | 25 | yield |
| 26 | FileUtils.rm(LOCK_FILE_PATH) if File.exist?(LOCK_FILE_PATH) |
| 27 | 27 | rescue TaskLockError |
| 28 | | $stderr.puts "Task lockfile exists" |
| 28 | $stderr.puts "Task lockfile exists - long running task_performer?" |
| 29 | 29 | exit(1) |
| 30 | | ensure |
| 31 | | FileUtils.rm(LOCK_FILE_PATH) |
| 32 | 30 | end |
| 33 | 31 | end |
| 34 | 32 | |
| toggle raw diff |
--- a/script/task_performer
+++ b/script/task_performer
@@ -6,29 +6,27 @@ require "fileutils"
LOCK_FILE_PATH = File.join(Dir.tmpdir, "gitorious_task_lockfile")
ENV["PATH"] = "/usr/local/bin/:/opt/local/bin:#{ENV["PATH"]}"
-if File.exist?(LOCK_FILE_PATH)
- $stderr.puts "Task lockfile '#{LOCK_FILE_PATH}' exists!"
- exit(1)
-end
-
ENV["RAILS_ENV"] ||= "production"
require File.dirname(__FILE__) + "/../config/environment"
-
class TaskLockError < StandardError; end
def with_lock(&block)
begin
if File.exist?(LOCK_FILE_PATH)
- raise TaskLockError
+ pid = IO.read( LOCK_FILE_PATH ).to_i
+ if File.directory?("/proc/#{pid}/")
+ raise TaskLockError
+ else # STALE LOCK FILE
+ FileUtils.rm(LOCK_FILE_PATH)
+ end
end
- FileUtils.touch(LOCK_FILE_PATH)
+ File.open(LOCK_FILE_PATH,'w') { |f| f << $$ }
yield
+ FileUtils.rm(LOCK_FILE_PATH) if File.exist?(LOCK_FILE_PATH)
rescue TaskLockError
- $stderr.puts "Task lockfile exists"
+ $stderr.puts "Task lockfile exists - long running task_performer?"
exit(1)
- ensure
- FileUtils.rm(LOCK_FILE_PATH)
end
end
|