aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/message.rb4
-rw-r--r--filter/numlab/exercises/show/extract_properties/filter.rb25
-rwxr-xr-xlib/garbage_collection.sh9
-rw-r--r--lib/tasks/vip_count_exercises_with_ttl.rake25
-rw-r--r--lib/tasks/vip_count_exercises_without_ttl.rake25
-rw-r--r--lib/tasks/vip_garbage_collect_evaluations.rake22
-rw-r--r--lib/tasks/vip_garbage_collect_exercises.rake38
-rw-r--r--lib/tasks/vip_garbage_collect_results.rake22
-rw-r--r--lib/tasks/vip_garbage_collect_solutions.rake20
9 files changed, 189 insertions, 1 deletions
diff --git a/app/models/message.rb b/app/models/message.rb
index 7cfb417..24eb296 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -128,11 +128,13 @@ class Message < ActiveRecord::Base
# return first messages from fifo/lifo queue
def self.fifo_lifo_rest(namespace, ressource, participant_id, options={:queue_type => :fifo})
- find(:first, :readonly => false, :lock => true,
+ m=find(:all, :readonly => false, :lock => true,
+ :select => "messages.id",
:joins => [:ressource, { :membership_messages => { :membership => :participant } }],
:conditions => { :participants => { :id => participant_id },
:ressources => { :namespace => namespace, :ressource => ressource } },
:order => :messages.to_s+".id #{(options[:queue_type]==:fifo)?'ASC':'DESC'}")
+ if m.empty? then nil else find(m[0]) end
end
# get a record out of the message table
diff --git a/filter/numlab/exercises/show/extract_properties/filter.rb b/filter/numlab/exercises/show/extract_properties/filter.rb
new file mode 100644
index 0000000..d2a767a
--- /dev/null
+++ b/filter/numlab/exercises/show/extract_properties/filter.rb
@@ -0,0 +1,25 @@
+module Filter
+ def self.start
+ properties=FILTER_API.params[:properties]
+ return if properties.nil?
+ properties= properties.split(",")
+ properties_length= properties.length
+ obj= JSON.parse(FILTER_API.record.body)
+ i=0
+ body= ERB.new <<-'EOF',0,">"
+{ "Exercise" :
+ {
+<% properties.each do |e| %>
+<% i += 1 %>
+ "<%= e %>" : "<%= obj["Exercise"][e] %>"<% if i!=properties_length %>,
+<% end %>
+<% end %>
+
+ }
+}
+EOF
+
+ FILTER_API.record.body= body.result(binding)
+ #Message.destroy_msg(FILTER_API.record)
+ end
+end
diff --git a/lib/garbage_collection.sh b/lib/garbage_collection.sh
new file mode 100755
index 0000000..ac4e73a
--- /dev/null
+++ b/lib/garbage_collection.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+#
+ps ax | grep -v 'grep.*ecs:gc_anonymous_participants' | grep -q 'rake ecs:gc_anonymous_participants' || RAILS_ENV=production bundle exec rake ecs:gc_anonymous_participants
+ps ax | grep -v 'grep.*ecs:gc_sys_auths' | grep -q 'rake ecs:gc_sys_auths' || RAILS_ENV=production bundle exec rake ecs:gc_sys_auths
+ps ax | grep -v 'grep.*ecs:gc_sub_participants' | grep -q 'rake ecs:gc_sub_participants' || RAILS_ENV=production bundle exec rake ecs:gc_sub_participants
+ps ax | grep -v 'grep.*vip:gc_exercises' | grep -q 'rake vip:gc_exercises' || RAILS_ENV=production bundle exec rake vip:gc_exercises
+ps ax | grep -v 'grep.*vip:gc_evaluations' | grep -q 'rake vip:gc_evaluations' || RAILS_ENV=production bundle exec rake vip:gc_evaluations
+ps ax | grep -v 'grep.*vip:gc_results' | grep -q 'rake vip:gc_results' || RAILS_ENV=production bundle exec rake vip:gc_results
+ps ax | grep -v 'grep.*vip:gc_solutions' | grep -q 'rake vip:gc_solutions' || RAILS_ENV=production bundle exec rake vip:gc_solutions
diff --git a/lib/tasks/vip_count_exercises_with_ttl.rake b/lib/tasks/vip_count_exercises_with_ttl.rake
new file mode 100644
index 0000000..2642fbc
--- /dev/null
+++ b/lib/tasks/vip_count_exercises_with_ttl.rake
@@ -0,0 +1,25 @@
+namespace :vip do
+ desc "Count exercises with TTL attribute."
+ task :count_ttl_exercises => :environment do
+ ttl=[]
+ noexercise=0
+ Message.for_resource("numlab", "exercises").sort{|x,y| x.created_at <=> y.created_at}.each do |msg|
+ begin
+ if JSON.parse(msg.body)['Exercise'].nil?
+ noexercise+= 1
+ elsif !JSON.parse(msg.body)['Exercise']['TTL'].nil?
+ puts "Exercise (#{msg.id}) with TTL = " + JSON.parse(msg.body)['Exercise']['TTL'].to_s
+ ttl << msg
+ 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
+ puts "ID's of exercises with ttl: " + ttl.map{|m| m.id}.join(', ')
+ puts "noexercise: "+noexercise.to_s
+ puts "Number of exercises: #{Message.for_resource("numlab", "exercises").length-noexercise}"
+ puts "Number of exercises with ttl: " + ttl.length.to_s
+ end
+end
diff --git a/lib/tasks/vip_count_exercises_without_ttl.rake b/lib/tasks/vip_count_exercises_without_ttl.rake
new file mode 100644
index 0000000..0adfc14
--- /dev/null
+++ b/lib/tasks/vip_count_exercises_without_ttl.rake
@@ -0,0 +1,25 @@
+namespace :vip do
+ desc "Count exercises without TTL attribute."
+ task :count_no_ttl_exercises => :environment do
+ # ttl= 20*60 # 20 minutes
+ ttl= 30*24*3600 # 9999 years
+ nottl=0
+ noexercise=0
+ Message.for_resource("numlab", "exercises").sort{|x,y| x.created_at <=> y.created_at}.each do |msg|
+ begin
+ if JSON.parse(msg.body)['Exercise'].nil?
+ noexercise+= 1
+ elsif JSON.parse(msg.body)['Exercise']['TTL'].nil?
+ nottl+= 1
+ 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
+ puts "Number of exercises: #{Message.for_resource("numlab", "exercises").length-noexercise}"
+ puts "nottl: "+nottl.to_s
+ puts "noexercise: "+noexercise.to_s
+ end
+end
diff --git a/lib/tasks/vip_garbage_collect_evaluations.rake b/lib/tasks/vip_garbage_collect_evaluations.rake
new file mode 100644
index 0000000..c9d963a
--- /dev/null
+++ b/lib/tasks/vip_garbage_collect_evaluations.rake
@@ -0,0 +1,22 @@
+namespace :vip do
+ desc "Delete old evaluations."
+ task :gc_evaluations => :environment do
+ ttl= 15.hours.ago
+ i=0
+ Message.for_resource("numlab", "evaluations").for_not_removed.each do |msg|
+ begin
+ if msg.created_at < ttl
+ m = Message.find(msg.id)
+ m.destroy_as_sender
+ i+=1
+ txt= "gc_evaluations: #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ RAILS_DEFAULT_LOGGER.info txt
+ puts txt
+ end
+ end
+ end
+ txt= "gc_evaluations: Deleted #{i} evaluations."
+ RAILS_DEFAULT_LOGGER.info txt
+ puts txt
+ end
+end
diff --git a/lib/tasks/vip_garbage_collect_exercises.rake b/lib/tasks/vip_garbage_collect_exercises.rake
new file mode 100644
index 0000000..ae3e744
--- /dev/null
+++ b/lib/tasks/vip_garbage_collect_exercises.rake
@@ -0,0 +1,38 @@
+namespace :vip do
+ desc "Deletes old exercises."
+ task :gc_exercises => :environment do
+ ttl = 15.hours.ago
+ num=0
+ Message.for_resource("numlab", "exercises").for_not_removed.sort{|x,y| x.created_at <=> y.created_at}.each do |msg|
+ begin
+ 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
+ if msg.created_at < ttl
+ m= Message.find(msg.id)
+ m.destroy_as_sender
+ num+=1
+ 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
+ end
+ 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
+ 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}"
+ puts txt
+ RAILS_DEFAULT_LOGGER.info txt
+ end
+end
diff --git a/lib/tasks/vip_garbage_collect_results.rake b/lib/tasks/vip_garbage_collect_results.rake
new file mode 100644
index 0000000..0c4618e
--- /dev/null
+++ b/lib/tasks/vip_garbage_collect_results.rake
@@ -0,0 +1,22 @@
+namespace :vip do
+ desc "Delete old results."
+ task :gc_results => :environment do
+ ttl= 15.hours.ago
+ i=0
+ Message.for_resource("numlab", "results").each do |msg|
+ begin
+ if msg.created_at < ttl
+ m = Message.find(msg.id)
+ m.destroy_as_sender
+ i+=1
+ txt= "gc_results: #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ RAILS_DEFAULT_LOGGER.info txt
+ #puts txt
+ end
+ end
+ end
+ txt= "gc_results: Deleted #{i} results."
+ RAILS_DEFAULT_LOGGER.info txt
+ puts txt
+ end
+end
diff --git a/lib/tasks/vip_garbage_collect_solutions.rake b/lib/tasks/vip_garbage_collect_solutions.rake
new file mode 100644
index 0000000..3c99fbf
--- /dev/null
+++ b/lib/tasks/vip_garbage_collect_solutions.rake
@@ -0,0 +1,20 @@
+namespace :vip do
+ desc "Delete old solutions."
+ task :gc_solutions => :environment do
+ ttl= 15.hours.ago
+ i=0
+ Message.for_resource("numlab", "solutions").for_not_removed.each do |msg|
+ if msg.created_at < ttl
+ m = Message.find(msg.id)
+ m.destroy_as_sender
+ i+=1
+ txt= "gc_solutions: #{msg.ressource.namespace}/#{msg.ressource.ressource}/#{msg.id.to_s}"
+ RAILS_DEFAULT_LOGGER.info txt
+ #puts txt
+ end
+ end
+ txt= "gc_solutions: Deleted #{i} solutions."
+ RAILS_DEFAULT_LOGGER.info txt
+ puts txt
+ end
+end