aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2015-12-18 20:42:05 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2016-01-11 08:57:58 +0100
commit05b54522d130ff25110c68db94a0c50c64f42a51 (patch)
tree7f70b01cf30c32d2565fd7cce7e8bec7e096219b
parent3746f5d94921b2d791f21ea954d2fb1d54c88fc9 (diff)
downloadvipeval-05b54522d130ff25110c68db94a0c50c64f42a51.tar.gz
vipeval-05b54522d130ff25110c68db94a0c50c64f42a51.zip
New result event processing.
-rw-r--r--Gemfile2
-rw-r--r--lib/main_loop.rb10
-rw-r--r--lib/result_event.rb44
3 files changed, 45 insertions, 11 deletions
diff --git a/Gemfile b/Gemfile
index 4beb20a..e9952e8 100644
--- a/Gemfile
+++ b/Gemfile
@@ -25,9 +25,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
-
gem 'daemons-rails'
-
gem 'rest-client'
gem 'minitest-rails', group: [:development, :test]
diff --git a/lib/main_loop.rb b/lib/main_loop.rb
index 87cd86e..1a14c3a 100644
--- a/lib/main_loop.rb
+++ b/lib/main_loop.rb
@@ -30,7 +30,7 @@ class MainLoop
JobEvent.new.process(evbody)
elsif evbody[0]["ressource"].start_with?(APP_CONFIG["eventtypes"]["result"]["name"])
Rails.logger.info "***** received \"#{APP_CONFIG["eventtypes"]["result"]["name"]}\" event type"
- process_result_event(evbody)
+ ResultEvent.new.process(evbody)
else
Rails.logger.info "***** Unknown event: #{evbody[0]}"
end
@@ -58,14 +58,6 @@ class MainLoop
@ecs.connection["sys/events/fifo"].post ""
end
- def process_result_event(evbody)
- path= evbody[0]['ressource']
- result= @ecs.connection[path].delete
- Rails.logger.info "***** MainLoop#process_result_event: #{path} = #{result}"
- # remove exercise referenced through solution embedded in result
- path= URI(JSON::parse(result)["Result"]["Solution"]["exercise"]).path[1..-1]
- @ecs.connection[path].delete
- end
end
diff --git a/lib/result_event.rb b/lib/result_event.rb
new file mode 100644
index 0000000..478ccd7
--- /dev/null
+++ b/lib/result_event.rb
@@ -0,0 +1,44 @@
+class ResultEvent
+ def initialize
+ @ecs=HttpEcs.instance
+ end
+
+ def process(evbody)
+ path= evbody[0]['ressource']
+ resultr= @ecs.connection[path].delete
+ result= JSON::parse(resultr)
+ Rails.logger.info "***** ResultEvent#process: #{path} = #{result}"
+
+ # remove exercise referenced through solution embedded in result
+ path= URI(result["Result"]["Solution"]["exercise"]).path[1..-1]
+ @ecs.connection[path].delete do |response, request, result, &block|
+ case response.code
+ when 404
+ Rails.logger.info "***** ResultEvent#process: garbage collect: resource = #{path} not found (404)"
+ else
+ response.return!(request, result, &block)
+ end
+ end
+
+ points= -1
+ result["Result"]["elements"].each do |e|
+ case e["MIMEtype"]
+ when "text/plain"
+ if (val=e["value"]).strip.start_with?("*** Score:")
+ points= val.strip.split(":")[1].to_i
+ break
+ end
+ end
+ end
+ p= {}
+
+ p[:points]= points.to_i
+ p[:identifier]= result["Result"]["Solution"]["evaluationService"]["jobID"]
+ receiver= result["Result"]["Solution"]["evaluationService"]["jobSender"]
+ body= "{\"Points\": #{p.to_json} }"
+ Rails.logger.info "***** ResultEvent#process points body = #{body}, points receiver mid = #{receiver}"
+ response= @ecs.connection[APP_CONFIG["resources"]["points"]["name"]].post body, {"X-EcsReceiverMemberships" => receiver} do |response, request, result|
+ Rails.logger.info "***** ResultEvent#process post response headers: #{response.headers}"
+ end
+ end
+end