Module: SingleRunningChecker
- Defined in:
- lib/single_running_checker.rb
Instance Method Summary collapse
Instance Method Details
#task_running?(task_name, only_check = false) ⇒ Boolean
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/single_running_checker.rb', line 3 def task_running?(task_name, only_check=false) pid_file = File.join(Rails.root, "tmp", "pids", task_name+".pid") if File.exists? pid_file pid = File.read(pid_file) if pid proc = Sys::ProcTable.ps(pid.to_i) if proc && proc.cmdline =~ /#{task_name}/ puts "process with pid #{pid} already runinng" return true end end end open(pid_file, 'w') { |f| f << Process.pid.to_s } unless only_check return false end |