aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <freeit@nflexpvipecs.rus.uni-stuttgart.de>2016-01-11 15:25:18 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-02-12 05:55:55 +0100
commita6078f386f4260babb79bc5c88f25ed4fab99497 (patch)
tree80ccd4b1c22b24a1e1eb309c8f12b7fbf875545e
parent340b43752294f013b6bfa73722e459438fc045f5 (diff)
downloadecs2-a6078f386f4260babb79bc5c88f25ed4fab99497.tar.gz
ecs2-a6078f386f4260babb79bc5c88f25ed4fab99497.zip
Change vip garbage collections.
-rw-r--r--lib/tasks/vip_garbage_collect_exercises.rake27
-rw-r--r--lib/tasks/vip_garbage_collect_results.rake27
2 files changed, 34 insertions, 20 deletions
diff --git a/lib/tasks/vip_garbage_collect_exercises.rake b/lib/tasks/vip_garbage_collect_exercises.rake
index 7ce4384..9086f8c 100644
--- a/lib/tasks/vip_garbage_collect_exercises.rake
+++ b/lib/tasks/vip_garbage_collect_exercises.rake
@@ -1,28 +1,33 @@
namespace :vip do
desc "Deletes old exercises."
task :gc_exercises => :environment do
- #ttl= 20*60 # 20 minutes
- ttl= 6*30*24*3600 # 6 months
num=0
Message.for_resource("numlab", "exercises").sort{|x,y| x.created_at <=> y.created_at}.each do |msg|
begin
- body= JSON.parse(msg.body)
+ unless (ttl=JSON.parse(msg.body)['Exercise']['TTL'])
+ txt = "gc_exercises: don't delete permanent exercise: #{msg.id}"
+ puts txt
+ RAILS_DEFAULT_LOGGER.info txt
+ next
+ end
post_time= JSON.parse(msg.body)['Exercise']['postTime']
- diff_time= Time::now.utc - Time::utc(*ParseDate::parsedate(post_time)) - ttl
- if diff_time >= 0
+ if Time.parse(post_time) < ttl.seconds.ago
msg.destroy_as_sender
num+=1
- txt= "Filter: delete message (#{Time::utc(*ParseDate::parsedate(post_time))}): #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ txt= "gc_exercises: delete message (#{Time.parse(post_time).httpdate}): #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
RAILS_DEFAULT_LOGGER.info txt
- puts txt
+ #puts txt
end
rescue JSON::ParserError, Exception
- txt= "Filter Exception: "+$!.class.to_s+": #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
- RAILS_DEFAULT_LOGGER.error txt
- puts txt
+ txt= "gc_exercises:Exception: "+$!.class.to_s+": #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ RAILS_DEFAULT_LOGGER.info txt
+ #puts txt
+ tmp_msg=Message.find(msg.id)
+ tmp_msg.destroy_as_sender
+ num+=1
end
end
- txt= "Number of deleted messages: #{num}"
+ txt= "gc_exercises: Number of deleted exercises: #{num}"
puts txt
RAILS_DEFAULT_LOGGER.info txt
end
diff --git a/lib/tasks/vip_garbage_collect_results.rake b/lib/tasks/vip_garbage_collect_results.rake
index ef65d29..36b60ec 100644
--- a/lib/tasks/vip_garbage_collect_results.rake
+++ b/lib/tasks/vip_garbage_collect_results.rake
@@ -1,19 +1,28 @@
namespace :vip do
desc "Delete old results."
task :gc_results => :environment do
- # ttl= 20*60 # 20 minutes
- ttl= 1.month
- timenow= Time.now
+ ttl= 2.days.ago
i=0
Message.for_resource("numlab", "results").each do |msg|
- if msg.created_at < (timenow - ttl)
- i+=1
- msg.destroy_as_sender
- txt= "Service: garbage collect result: #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ begin
+ if msg.created_at < ttl
+ i+=1
+ msg.destroy_as_sender
+ txt= "gc_results: #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ RAILS_DEFAULT_LOGGER.info txt
+ #puts txt
+ end
+ rescue ActiveRecord::ReadOnlyRecord
+ txt= "gc_results:Exception: "+$!.class.to_s+": Delete readonly results #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
RAILS_DEFAULT_LOGGER.info txt
- #puts txt
+ puts txt
+ tmp_msg=Message.find(msg.id)
+ tmp_msg.destroy_as_sender
+ i+=1
end
end
- puts "\nDeleted #{i} results."
+ txt= "gc_results: Deleted #{i} results."
+ RAILS_DEFAULT_LOGGER.info txt
+ puts txt
end
end