diff options
author | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2012-11-04 23:25:38 +0100 |
---|---|---|
committer | Heiko Bernloehr <Heiko.Bernloehr@FreeIT.de> | 2012-11-04 23:26:47 +0100 |
commit | f4fc46b15994a39ed493469fd08b193476c19580 (patch) | |
tree | 7a562143c03867cf3e70c129f43e095a3fcbf607 | |
parent | dd365198e5a718c77ed960ac80d8ba32a6d10bfe (diff) | |
download | ecs2-f4fc46b15994a39ed493469fd08b193476c19580.tar.gz ecs2-f4fc46b15994a39ed493469fd08b193476c19580.zip |
Changed auths garbage collection.
-rw-r--r-- | lib/tasks/ecs_garbage_collect_auths.rake | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/lib/tasks/ecs_garbage_collect_auths.rake b/lib/tasks/ecs_garbage_collect_auths.rake index 606ae82..072600b 100644 --- a/lib/tasks/ecs_garbage_collect_auths.rake +++ b/lib/tasks/ecs_garbage_collect_auths.rake @@ -1,24 +1,50 @@ namespace :ecs do - desc "Deletes outtimed authorization tokens." + desc "Deletes outtimed authorization tokens (needs ps system command)." task :gc_sys_auths => :environment do - ps= `ps ax | grep -v 'grep' | grep -v "^[ \t]*#{Process.pid}" | grep 'rake ecs:gc_sys_auths'` - if !ps.empty? - RAILS_DEFAULT_LOGGER.info "GC: there is already running a ecs:gc_sys_auths process. Aborting." - puts "GC: There is already running a ecs:gc_sys_auths process. Aborting." - exit 1 + gc_sys_auths_pid= "#{Rails.root}/tmp/pids/gc_sys_auths.pid" + if File.exists?(gc_sys_auths_pid) + pid= "" + gc_sys_auths_is_running= false + File.open(gc_sys_auths_pid,"r") do |f| + pid= f.readline.strip + end + p= open("|ps ax") + p.each_line do |line| + if line.index(pid) + gc_sys_auths_is_running= true + break + end + end + p.close + if gc_sys_auths_is_running + RAILS_DEFAULT_LOGGER.info "GC: there seems to be already running a ecs:gc_sys_auths process (#{gc_sys_auths_pid}). Aborting." + puts "GC: there seems to be already running a ecs:gc_sys_auths process (#{gc_sys_auths_pid}). Aborting." + raise 'gc_sys_auths.pid file exists!' + end + end + File.open(gc_sys_auths_pid,"w") do |f| + f.puts "#{Process.pid}" end - RAILS_DEFAULT_LOGGER.info "GC: Searching for outtimed auths ..." - puts "GC: Searching for outtimed auths ..." - Message.all.each do |m| - if m.auth - if ! m.test_auths_validation_window - m.destroy_as_sender - RAILS_DEFAULT_LOGGER.info "GC: garbage collect auths token with id=#{m.id}." - puts "delete outtimed authorization token with id=#{m.id}" + begin + sleep 5 + RAILS_DEFAULT_LOGGER.info "GC: Searching for outtimed auths ..." + puts "GC: Searching for outtimed auths ..." + Message.all.each do |m| + if m.auth + if ! m.test_auths_validation_window + m.destroy_as_sender + RAILS_DEFAULT_LOGGER.info "GC: garbage collect auths token with id=#{m.id}." + puts "delete outtimed authorization token with id=#{m.id}" + end end end + RAILS_DEFAULT_LOGGER.info "GC: Searching for outtimed auths done." + puts "GC: Searching for outtimed auths done." + ensure + begin + #File.delete(gc_sys_auths_pid) + rescue + end end - RAILS_DEFAULT_LOGGER.info "GC: Searching for outtimed auths done." - puts "GC: Searching for outtimed auths done." end end |