aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <freeit@nflexpvipecs.rus.uni-stuttgart.de>2016-02-12 05:23:45 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-02-12 06:19:59 +0100
commitf46014c8ae74c14b2ed9f9ea0b311e834c847bd7 (patch)
treef6a77964581e060a820e488d14dd9e3490577182
parent2d2a1d7b95c0c4806e1b987cdeaf5eda1f849048 (diff)
downloadecs2-f46014c8ae74c14b2ed9f9ea0b311e834c847bd7.tar.gz
ecs2-f46014c8ae74c14b2ed9f9ea0b311e834c847bd7.zip
Now test on created_at for deleting exercises in vip:gc_exercises
-rw-r--r--lib/tasks/vip_garbage_collect_exercises.rake22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/tasks/vip_garbage_collect_exercises.rake b/lib/tasks/vip_garbage_collect_exercises.rake
index 9086f8c..ae3e744 100644
--- a/lib/tasks/vip_garbage_collect_exercises.rake
+++ b/lib/tasks/vip_garbage_collect_exercises.rake
@@ -1,30 +1,34 @@
namespace :vip do
desc "Deletes old exercises."
task :gc_exercises => :environment do
+ ttl = 15.hours.ago
num=0
- Message.for_resource("numlab", "exercises").sort{|x,y| x.created_at <=> y.created_at}.each do |msg|
+ Message.for_resource("numlab", "exercises").for_not_removed.sort{|x,y| x.created_at <=> y.created_at}.each do |msg|
begin
- unless (ttl=JSON.parse(msg.body)['Exercise']['TTL'])
+ unless (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']
- if Time.parse(post_time) < ttl.seconds.ago
- msg.destroy_as_sender
+ if msg.created_at < ttl
+ m= Message.find(msg.id)
+ m.destroy_as_sender
num+=1
- txt= "gc_exercises: delete message (#{Time.parse(post_time).httpdate}): #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ txt= "gc_exercises: delete message (#{msg.created_at.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
+ rescue JSON::ParserError
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
+ #num+=1
+ rescue ActiveRecord::RecordNotFound
+ txt= "gc_exercises:Exception: "+$!.class.to_s+": #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ RAILS_DEFAULT_LOGGER.info txt
end
end
txt= "gc_exercises: Number of deleted exercises: #{num}"