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
|
def increasejobscounter
|
||||||
jobscounter = 0
|
jobscounter = 0
|
||||||
if File.exists(COUNTERFILE)
|
if FileTest.exists?(COUNTERFILE)
|
||||||
File.new(COUNTERFILE, "r+").flock(File::LOCK_EX){|file|
|
File.new(COUNTERFILE).flock(File::LOCK_EX)
|
||||||
jobscounter = file.read.to_i
|
File.open(COUNTERFILE, "r+"){|file|
|
||||||
|
jobscounter = file.read
|
||||||
|
if jobscounter.empty?
|
||||||
|
jobscounter = 0
|
||||||
|
end
|
||||||
|
jobscounter = jobscounter.to_i
|
||||||
jobscounter += 1
|
jobscounter += 1
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
file.puts jobscounter
|
file.puts jobscounter
|
||||||
}
|
}
|
||||||
|
File.new(COUNTERFILE, "r+").flock(File::LOCK_UN)
|
||||||
else
|
else
|
||||||
File.new(COUNTERFILE, "w").flock(File::LOCK_EX){|file|
|
File.open(COUNTERFILE, "w"){|file|
|
||||||
|
File.new(COUNTERFILE).flock(File::LOCK_EX)
|
||||||
jobscounter = 1
|
jobscounter = 1
|
||||||
file.puts jobscounter
|
file.puts jobscounter
|
||||||
}
|
}
|
||||||
|
File.new(COUNTERFILE, "r+").flock(File::LOCK_UN)
|
||||||
end
|
end
|
||||||
return jobscounter
|
return jobscounter
|
||||||
end
|
end
|
||||||
|
|
||||||
def addjob
|
def addjob
|
||||||
p ARGV.join(" ")
|
p ARGV.join(" ")
|
||||||
|
jobnumber=sprintf("%06d", increasejobscounter)
|
||||||
|
p jobnumber
|
||||||
end
|
end
|
||||||
|
|
||||||
def addjobfromfile
|
def addjobfromfile
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue