lib/rbatch.rb in rbatch-1.7.0 vs lib/rbatch.rb in rbatch-1.8.0
- old
+ new
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
-
+require 'digest'
module RBatch
@@program_name = $PROGRAM_NAME
module_function
def program_name=(f) ; @@program_name = f ; end
def program_name ; @@program_name ; end
@@ -29,23 +29,33 @@
end
else
return nil
end
end
+ def double_run_check
+ # double run check
+ if ( RBatch::common_config != nil && RBatch::common_config["forbid_double_run"] )
+ lock_file="rbatch_lock_" + Digest::MD5.hexdigest(@@program_name)
+ if Dir.exists? RBatch::tmp_dir
+ Dir::foreach(RBatch::tmp_dir) do |f|
+ if (Regexp.new(lock_file) =~ f)
+ raise RBatchException, "Script double run is forbid about \"#{RBatch::program_name}\""
+ end
+ end
+ end
+ # make lockfile
+ Tempfile::new(lock_file,RBatch::tmp_dir)
+ end
+ end
+
+ def double_run_lock_file ; ; end
end
+# RBatch Exception
+class RBatchException < Exception ; end
+
+# main
require 'rbatch/log'
require 'rbatch/config'
require 'rbatch/cmd'
-# double run check
-if ( RBatch::common_config != nil && RBatch::common_config["forbid_double_run"] )
- if Dir.exists? RBatch::tmp_dir
- Dir::foreach(RBatch::tmp_dir) do |f|
- if (/rbatch_lock/ =~ f)
- raise "Can not start RBatch. RBatch lock file exists (#{RBatch::tmp_dir}#{f})."
- end
- end
- end
- # make lockfile
- Tempfile::new("rbatch_lock",RBatch::tmp_dir)
-end
+RBatch::double_run_check