From da78ddf82bdc7cc56e997263a4d5a7956009e70f Mon Sep 17 00:00:00 2001 From: mguetlein Date: Wed, 4 May 2011 15:29:13 +0200 Subject: return correct error status (to fix inconsistent task status codes), fix error report (broke whith redis switch) --- application.rb | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/application.rb b/application.rb index 673cc4d..ee7bcbb 100644 --- a/application.rb +++ b/application.rb @@ -22,7 +22,18 @@ class Task < Ohm::Model attribute :waiting_for - attribute :errorReport + attribute :error_report_yaml + + # convenience method to store object in redis + def errorReport + YAML.load(self.error_report_yaml) if self.error_report_yaml + end + + # convenience method to store object in redis + def errorReport=(er) + self.error_report_yaml = er.to_yaml + end + def metadata { @@ -61,7 +72,22 @@ end get '/:id/?' do task = Task[params[:id]] halt 404, "Task '#{params[:id]}' not found." unless task - code = task.hasStatus == "Running" ? 202 : 200 + + # set task http code according to status + case task.hasStatus + when "Running" + code = 202 + when "Cancelled" + code = 503 + when "Error" + if task.errorReport + code = task.errorReport.http_code.to_i + else + code = 500 + end + else #Completed + code = 200 + end case request.env['HTTP_ACCEPT'] when /yaml/ @@ -82,10 +108,14 @@ get '/:id/?' do t = OpenTox::Task.new task.uri t.add_metadata task.metadata t.add_error_report task.errorReport - halt t.to_rdfxml + halt code, t.to_rdfxml when /text\/uri\-list/ response['Content-Type'] = 'text/uri-list' - halt code, task.resultURI + if t.hasStatus=="Completed" + halt code, t.resultURI + else + halt code, t.uri + end else halt 400, "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported, valid Accept-Headers are \"application/rdf+xml\" and \"application/x-yaml\"." end @@ -158,8 +188,8 @@ put '/:id/:hasStatus/?' do halt 404,"Task #{params[:id]} not found." unless task task.hasStatus = params[:hasStatus] unless /pid/ =~ params[:hasStatus] task.description = params[:description] if params[:description] - #task.errorReport = YAML.load(params[:errorReport]) if params[:errorReport] - task.errorReport = params[:errorReport] if params[:errorReport] + # error report comes as yaml string + task.error_report_yaml = params[:errorReport] if params[:errorReport] case params[:hasStatus] when "Completed" @@ -187,7 +217,7 @@ put '/:id/:hasStatus/?' do rescue end end - LOGGER.debug("Aborting task "+task.uri.to_s) + LOGGER.debug("Aborting task '"+task.uri.to_s+"' with pid: '"+task.pid.to_s+"'") Process.kill(9,task.pid.to_i) unless task.pid.nil? task.pid = nil else @@ -195,7 +225,6 @@ put '/:id/:hasStatus/?' do end halt 500,"could not save task" unless task.save - end # Delete a task -- cgit v1.2.3 From ce541855d49ce6d40535a4777f08d990ab7b0122 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Thu, 5 May 2011 11:50:50 +0200 Subject: bugfix for correct task status code fix --- application.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application.rb b/application.rb index ee7bcbb..9969fd6 100644 --- a/application.rb +++ b/application.rb @@ -111,10 +111,10 @@ get '/:id/?' do halt code, t.to_rdfxml when /text\/uri\-list/ response['Content-Type'] = 'text/uri-list' - if t.hasStatus=="Completed" - halt code, t.resultURI + if task.hasStatus=="Completed" + halt code, task.resultURI else - halt code, t.uri + halt code, task.uri end else halt 400, "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported, valid Accept-Headers are \"application/rdf+xml\" and \"application/x-yaml\"." -- cgit v1.2.3 From fde80560c28fb67af46b0376cb593b9889637692 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Wed, 11 May 2011 14:49:15 +0200 Subject: fix task.to_rdf for tasks without error report --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.rb b/application.rb index 9969fd6..e349b3d 100644 --- a/application.rb +++ b/application.rb @@ -107,7 +107,7 @@ get '/:id/?' do response['Content-Type'] = 'application/rdf+xml' t = OpenTox::Task.new task.uri t.add_metadata task.metadata - t.add_error_report task.errorReport + t.add_error_report task.errorReport if task.errorReport halt code, t.to_rdfxml when /text\/uri\-list/ response['Content-Type'] = 'text/uri-list' -- cgit v1.2.3 From 787d9f3d013bc7c7ddb9de28bd0bb5f6c6c16277 Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 23 May 2011 13:37:32 +0200 Subject: configure new version requested opentox-ruby gem --- application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.rb b/application.rb index e349b3d..850e85f 100644 --- a/application.rb +++ b/application.rb @@ -1,5 +1,5 @@ require 'rubygems' -gem "opentox-ruby", "~> 1" +gem "opentox-ruby", "~> 2" require 'opentox-ruby' set :lock, true -- cgit v1.2.3