aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2014-07-30 01:11:31 +0200
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-01-27 01:51:20 +0100
commitc1dc11fa754458d5b49efad0203be0a96a1cbc63 (patch)
treecb785da5d26c46fd167e3002274ce52df70d6b4a
parentd3d24952b04364a6615ea93fafdf474884448030 (diff)
downloadecs2-c1dc11fa754458d5b49efad0203be0a96a1cbc63.tar.gz
ecs2-c1dc11fa754458d5b49efad0203be0a96a1cbc63.zip
New rake task vip:gc_exercises.
Delete old exercises. You have to edit the task file to change the time from when the exercises will be deleted.
-rw-r--r--lib/tasks/vip_garbage_collect_exercises.rake24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/tasks/vip_garbage_collect_exercises.rake b/lib/tasks/vip_garbage_collect_exercises.rake
new file mode 100644
index 0000000..c7a0b31
--- /dev/null
+++ b/lib/tasks/vip_garbage_collect_exercises.rake
@@ -0,0 +1,24 @@
+namespace :vip do
+ desc "Delete old exercises."
+ task :gc_exercises => :environment do
+ # ttl= 20*60 # 20 minutes
+ ttl= 30*24*3600 # 9999 years
+ Message.for_resource("numlab", "exercises").sort{|x,y| x.created_at <=> y.created_at}.each do |msg|
+ begin
+ body= JSON.parse(msg.body)
+ post_time= JSON.parse(msg.body)['Exercise']['postTime']
+ diff_time= Time::now.utc - Time::utc(*ParseDate::parsedate(post_time)) - ttl
+ if diff_time >= 0
+ Message::destroy_msg(msg)
+ txt= "Filter: delete message (#{Time::utc(*ParseDate::parsedate(post_time))}): #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ RAILS_DEFAULT_LOGGER.info 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
+ end
+ end
+ end
+end