locking++
This commit is contained in:
parent
e44b81f854
commit
8b8a8c560c
1 changed files with 14 additions and 4 deletions
18
pbatch/pb.rb
18
pbatch/pb.rb
|
|
@ -79,24 +79,34 @@ end
|
|||
|
||||
def increasejobscounter
|
||||
jobscounter = 0
|
||||
if File.exists(COUNTERFILE)
|
||||
File.new(COUNTERFILE, "r+").flock(File::LOCK_EX){|file|
|
||||
jobscounter = file.read.to_i
|
||||
if FileTest.exists?(COUNTERFILE)
|
||||
File.new(COUNTERFILE).flock(File::LOCK_EX)
|
||||
File.open(COUNTERFILE, "r+"){|file|
|
||||
jobscounter = file.read
|
||||
if jobscounter.empty?
|
||||
jobscounter = 0
|
||||
end
|
||||
jobscounter = jobscounter.to_i
|
||||
jobscounter += 1
|
||||
file.seek(0)
|
||||
file.puts jobscounter
|
||||
}
|
||||
File.new(COUNTERFILE, "r+").flock(File::LOCK_UN)
|
||||
else
|
||||
File.new(COUNTERFILE, "w").flock(File::LOCK_EX){|file|
|
||||
File.open(COUNTERFILE, "w"){|file|
|
||||
File.new(COUNTERFILE).flock(File::LOCK_EX)
|
||||
jobscounter = 1
|
||||
file.puts jobscounter
|
||||
}
|
||||
File.new(COUNTERFILE, "r+").flock(File::LOCK_UN)
|
||||
end
|
||||
return jobscounter
|
||||
end
|
||||
|
||||
def addjob
|
||||
p ARGV.join(" ")
|
||||
jobnumber=sprintf("%06d", increasejobscounter)
|
||||
p jobnumber
|
||||
end
|
||||
|
||||
def addjobfromfile
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue